Query IP address location using python

Source: Internet
Author: User
Tags get ip
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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.