Mulagala Mulagala - 7 months ago 17
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.


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