Get external IP address with Python

Here’s a quick snippet of Python code (tested in 3.0) to quickly look up your external IP address over HTTP and display it:

import urllib.request
print(str(urllib.request.urlopen("http://automation.whatismyip.com/n09230945.asp").read(), "utf8"))

Tags:

3 Responses to “Get external IP address with Python”

  1. James says:

    Completely off the topic but cant find a better way to get a hold of you… do you still have your MX500Lib06.zip dll from a few years ago? The link is to this site but no longer works.

  2. George Helyar says:

    http://www.helyar.net/files/MX5000Lib06.zip

    I separated this code into a separate HID project and used the MX5000 as an example, so check out the sourceforce project libhidnet:

    http://sourceforge.net/projects/libhidnet/

    I haven’t worked on any of this for years though because my MX5000 keyboard died and I replaced it with one that wasn’t so terrible that I needed to write my own software for it just to make it usable.

  3. Guy says:

    Hello,
    Thank you for the tutorial it helped me get the external IP but I had to remove the “.request” part of the command. In other words I did:

    import urllib
    ip = str(urllib.urlopen(“http://www.whatismyip.com/automation/n09230945.asp”).read(), “utf8″)

    I am only using python2.6 I believe though.

Leave a Reply