Search code examples
pythonip-addresstcp

Discovering public IP programmatically


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


Solution

  • EDIT: curlmyip.com is no longer available. (thanks maxywb)

    Original Post:

    As of writing this post, curlmyip.com works. From the command line:

    curl curlmyip.com
    

    It's a third-party website, which may or may not be available a couple years down the road. But for the time being, it seems pretty simple and to the point.