Getting IP Address with Python

by Amit


Some python scripts to get the World IP Address of your machine

script 1

import urllib
checkIP = urllib.urlopen(“http://checkip.dyndns.org”).read()externalIP = checkIP.split()[-1].strip(“”)print externalIP

script 2

import re, urllib; print re.findall(“Your IP: (.+?)”, urllib.urlopen(“http://myip.dk/”).read())[0]

Advertisement