I can find my IP address using ifconfig or hostname -i command.
But how do I find my Public IP?
(I have a static public IP but I want to find it out using unix command)
feedback
|
This question came from our site for professional and enthusiast programmers.
|
One way: http://www.whatismyip.com/ | |||||||||||
feedback
|
|
You can request | |||||
feedback
|
|
If
then you can just parse the output from ifconfig for the IP addresses of the interfaces (the "inet addr:" part) to get the list of IP addresses of all your interfaces. The one IP address that is not in the private range (see http://en.wikipedia.org/wiki/IP%5Faddress#IPv4%5Fprivate%5Faddresses ) is your public IP address. The same list can also be obtained through
which may be easier to parse. If you do not have a direct internet connection (NAT etc.), there is no way to find your public IP address without external help (since your computer does not know it). Then you'll have to do it like in the other answers. | |||
|
feedback
|
|
One way is , you can make a request to the page at http://www.biranchi.com/ip.php it returns the IP address of your system | |||||||||||||||
feedback
|
|
A very simple anwser if you have internet access is:
Bear in mind, trusting third party sources for your IP might be problematic especially if what your doing with that data has special meaning. A more trustworthy way is to pick a known, trustworthy DNS server (ideally running DNSSEC) and query the hostname of the box with it, providing your DNS server contains such entries;
| |||
|
feedback
|
|
Okay...I know that this is WAY after the fact and probably not even worth posting, but here's my working solution.
Nice and simple. | |||
|
feedback
|
|
Duplicate of many other questions (hence my -1 vote). | |||
|
feedback
|
|
Google now displays your public IP address: http://www.google.com/search?q=ip | |||
|
feedback
|
|
If what you want is to find the external ip address on your router, you either ask the router itself for its wan address, or ask someone outside to get it for you.. for a manual way you can browse any of the above given sites that will return the ip of the incomming request. For an automated way, you can try :
which will get you the line that contains the ip address on the http response, then parse it out with sed, awk , etc | ||||
|
feedback
|
|
you can use just the shell to check your external ip, also using external providers
output | |||
|
feedback
|
|
I took a little different approach by using the STUN protocol which was designed for NAT Traversal. If you use Ubuntu you can just install the package "stun" by typing:
The package installs a STUN server which you probably wont need, but it also comes with a STUN test client which I used to solve this problem. Now you can retrieve your public IP with one (not so simple) command:
Now, what it does is: stun contacts the public STUN server "stunserver.org" and gets an answer back with your public IP, the rest of the command is just to filter out the IP from the output. | |||
|
feedback
|
|
A simple shell script solution can be found here: http://bash.cyberciti.biz/misc-shell/read-local-ip-address/ Works on Linux, FreeBSD, SunOS and Apple Darwin (with a minor modification). | |||
|
feedback
|
lynx --dump http://www.whatismyip.com/ | grep -o '[0-9].*\.[0-9].*\.[0-9].*\.[0-9].*' -m1 | |||
|
feedback
|
|
I'm doing this a lot, and from a lot of devices, so I made my own two services on a server : 1) php file on a webserver :
usage on a shell:
also working with ipv6:
On a router:
2) quick hack with a custom telnet server: xinetd spawning /usr/bin/env:
and then telnet to it :
works the same with a router:
This way you can make it work on your internal network, if some nat or proxy is involved in the communication and you'd like to know from what IP you appear. It doesn't require any third party service. | |||
|
feedback
|
|
I do this. It just gives me the IP without any third-party involvement.. ip addr show | grep eth0 | grep inet | tr -s " " | cut -f3 -d " " | cut -f1 -d "/" | |||
|
feedback
|