zoukankan      html  css  js  c++  java
  • Python3.* ip地址查询

    #encode:utf-8
    import  time
    import urllib.request
    import json
    f = "ip.txt"
    
    
    def ip_location(ip):
        url = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={%s}&co=&resource_id=6006&t=1529809984888&ie=utf8&oe=gbk&format=json&tn=baidu" % (ip)
        try:
            data = urllib.request.urlopen(url ).read()
            usr_data = data.decode("gbk","ignore")
            datadict=json.loads(usr_data)
            # print(datadict)
            addr = (datadict['data'][0])["location"]
            ip_name = (datadict['data'][0])["origip"]
            print (addr+":"+ip_name)
        except Exception as e:
            print(e)
    
    if __name__ =="__main__":
        with open(f)  as f:
            for i in f:
                ip_location(i.strip())
    

      

  • 相关阅读:
    19-10-31-B
    19-10-30-Night-V
    19-10-30-C
    19-10-29-Night-X
    19-10-29-Z
    19-10-28-A
    19-10-27-S
    19-10-26-Night-D
    留言板
    优秀博客存档
  • 原文地址:https://www.cnblogs.com/augustyang/p/9679796.html
Copyright © 2011-2022 走看看