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)
|
|
You can request |
|||||
|
|
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;
|
|||
|
|
|
One way: http://www.whatismyip.com/ |
|||||||||||||||
|
|
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. |
|||
|
|
|
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 |
|||||||||||||||
|
|
Google now displays your public IP address: http://www.google.com/search?q=ip |
|||||||||
|
|
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. |
|||
|
|
I wrote a simple and fast webservice for this.
You can ask for your IPv4:
Or IPv6:
And the API is documented on http://api.ident.me/ |
|||
|
|
|
Duplicate of many other questions (hence my -1 vote). |
|||
|
|
|
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. |
|||
|
|
|
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 |
||||
|
|
|
To avoid relying on external sources, I use expect, to telnet into my router and get the ip address of its public interface. Here's an example expect script:
I then execute the above script like this to get the public ip:
Of course, this is based on the assumption that I have admin access to the router, and its a linux-based router, with ifconfig command available. |
|||
|
|
|
you can use just the shell to check your external ip, also using external providers
output |
|||
|
|
|
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). |
|||
|
|
lynx --dump http://www.whatismyip.com/ | grep -o '[0-9].*\.[0-9].*\.[0-9].*\.[0-9].*' -m1 |
|||
|
|
|
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 "/" |
|||||
|
|
I'm doing this a lot, and from a lot of devices, so I made my own two services on a server :
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. |
||||
|
|
|
The simpliest way is to use http://ifconfig.me/, as suggested. On this page, you will know what command to use for what information you want to retrieve. For IP: curl ifconfig.meor curl ifconfig.me/ip For public Hostname: curl ifconfig.me/host For all informations in a XML file: curl ifconfig.me/all.xml etc... just check out http://ifconfig.me |
|||
|
|
|
||||
|
|
|
Here is another alternative that depends on hosts who's business resolves around managing dynamic IP rather that "public service" sites that may go away or change format. 1) Register your server at one of the many free dynamic dns services (e.g. no-ip.com) This will give you a DNS entry like xxx.no-ip.org. 2) Install the service's dynamic update tool (reports IP changes to service). To get the IP address in a script, just do:
Great for use in cron job to check if dynamic IP has changed and some configuration entries need to be changed. |
||||
|
|