Mulagala Mulagala - 1 year ago 105
Python Question

Finding network (external) IP addresses using Python

I want to know my internet provider (external) IP address (broadband or something else) with Python.

There are multiple machines are connected to that network. I tried in different way's but I got only the local and public IP my machine. How do I find my external IP address through Python?

Thanks in advance.

Answer Source

Use this script :

import urllib, json

data = json.loads(urllib.urlopen("").read())
print data["ip"]

Without json :

import urllib, re

data ='"([0-9.]*)"', urllib.urlopen("").read()).group(1)
print data
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download