Which is a pretty bad idea.Īlso, on my Arch system, the command you seem to be using to get the IP returns the UID of my user: $ ip route get 1ġ.0.0.0 via 192.168.1.1 dev enp0s31f6 src 192.168.1. Also, why would you run ssh with sudo? If you need to log into the remote as root, then you can do that ( ssh but it's very unlikely you would need to run ssh with sudo unless your ssh keys all belonged to root. (previous lines are http headers) This avoids the need for http client like wget or curl. Currently I am using c program but I want to do this using shell script. bash opens open a socket to icanhazip and sends an http request, the IP address is returned on the last non-empty line of the data returned. Use awk to print the 5th text block for Interface NAME. Use 'ip route get 8.8.8.8 ' to figure out which ACTIVE interface has the route to internet ( or currently being used ) Output should look like : 8.8.4.4 via 10.10.1.1 dev enp0s3 src 10.10.1.118 cache. You can do this with standard system calls. This is considerably more complicated than it needs to be. With the commandline before, I get 192.168.0.85 which is the IP address of em1. I want to get host name and (single) host address and save it to variable of type string using a bash shell script. Here's a small script to solve the problem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |