I'm trying to use just the IP address (inet) as a parameter in a script I wrote.
Is there an easy way in a unix terminal to get just the IP address, rather than looking through ifconfig
?
I'm trying to use just the IP address (inet) as a parameter in a script I wrote.
Is there an easy way in a unix terminal to get just the IP address, rather than looking through ifconfig
?
To get only the IP address on Mac OS X you can type the following command:
If you have limited environment, you may use this command:
You can also use the following command:
NOTE: This will only work if you have connectivity to the internet.
Here is my version, in which you can pass a list of interfaces, ordered by priority:
So if I'm connected with VPN, Wifi and ethernet, my VPN address (on interface tap0) will be returned. The script works on both linux and osx, and can take arguments if you want to override IFLIST
Note that if you want to use IPV6, you'll have to replace 'inet ' by 'inet6'.
This command will give you the exact ip address as you want in Ubuntu.
This returns only the ip address of your system.