This article will share with you the code that uses Python to query the geographic location of IP addresses based on the ip138 API. it is very practical and recommended to you. if you need it, you can refer to it. Use the IP138 database to query the geographic location of the domain name or IP address.
#-*-Coding: gbk-*-import urllib2import re try: while True: ipaddr = raw_input ("Enter IP Or Domain Name :") if ipaddr = "" or ipaddr = 'eg': break else: url = "http://www.ip138.com/ips138.asp? Ip = % s & action = 2 "% ipaddr u = urllib2.urlopen (url) s = u. read () # Get IP Address ip = re. findall (r' \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3} ', s) print "\ n ****** Below Result From IP138 Database *****" print "IP Address :", ip [0] # Get IP Address Location result = re. findall (r '(
.*?) ', S) for I in result: print I [4:-5] print "*" * 45 print "\ n" random T: print "Not Data Find"
The above is all the content of this article. I hope you will like it.