python method to obtain local and external network ip

  • 2020-05-10 18:21:48
  • OfStack

In this paper, an example is given to illustrate the method of python to obtain ip. Share with you for your reference. The details are as follows:

python retrieves the local ip from the web site that displays the ip address. This python code grabs the ip address information from the web site


import urllib
import re
print "we will try to open this url, in order to get IP Address"
url = "http://checkip.dyndns.org"
print url
request = urllib.urlopen(url).read()
theIP = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}",request)
print "your IP Address is: ", theIP

I hope this article is helpful to you in Python programming.


Related articles: