I'm behind a router, I need a simple command to discover my public ip (instead of googling what's my ip and clicking one the results)
Are there any standard protocols for this? I've heard about STUN but I don't know how can I use it?
P.S. I'm planning on writing a short python script to do it
This may be the easiest way. Parse the output of the following commands:
For example, I am on a Windows machine, but the same idea should work from unix too.
The 68.85.228.121 is a Comcast (my provider) router. We can ping that:
Voila! The 66.176.38.51 is my public IP.
As mentioned by several people, STUN is indeed the proper solution.
I have made a program that connects to http://automation.whatismyip.com/n09230945.asp it is is written in D an getting someone else to tell you what they see your ip as is probably the most reliable way:
Edit python code should be like:
If the network has an UpNp server running on the gateway you are able to talk to the gateway and ask it for your outside IP address.
another cheeky way: if your router has got the option to update it's web IP on DynDNS, you can get your own IP with something like:
curl api.infoip.io
- full detailscurl api.infoip.io/ip
- just the ip addresscurl api.infoip.io/country
- just the country name... and more of the same
you can view the docs at http://docs.ciokan.apiary.io/