• 批量查询IP的位置,ISP脚本(python)


    做资产盘点或者信息搜集时经常需要查询IP的的位置和运营商,故造轮子。

    使用接口http://ip.taobao.com

    • 优点:查询返回json格式字符串,便于处理,对新手友好
    • 缺点:无法使用域名查询
    # 查询IP
    import requests
    
    def cha(ip):
        url = 'http://ip.taobao.com/outGetIpInfo'
        headers = {
                'Accept':'*/*',
                'X-Requested-With':'XMLHttpRequest',
                'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
                'Content-Type': 'application/x-www-form-urlencoded',
                'Origin':'http://ip.taobao.com',
                'Referer':'http://ip.taobao.com/ipSearch',
                'Accept-Encoding':'gzip, deflate',
                'Accept-Language':'zh-CN,zh;q=0.9'
                }
        payload = {'ip':ip,'accessKey':'alibaba-inc'}
        res = requests.post(url,headers=headers,data=payload)
        di12 = res.json()
        guojia = di12['data']['country']
        sheng = di12['data']['region']
        chengshi = di12['data']['city']
        ip = di12['data']['ip']
        yys = di12['data']['isp']
        print(di12['msg'])
    #    print(type(res.text))
    #    return res.json()
        return ip+"[+]"+guojia+sheng+chengshi+" 运营商:"+yys
    
    if __name__ == "__main__":
     #   s1 = str(input("请输入IP: "))
    #    filename = str(input("File name: "))
        filename = 'IP_LIST.txt'  #ip列表文件
        file1 = open(filename,'r')
        try:
            for line in file1:
                ip = line.strip()
                print(cha(ip))
        except:
            print('error')
    ##    for line in file1:
    ##        if len(line) != 0:
    ##            ip = line.strip()
    ##            print(cha(ip))
    ##        else:
    ##            print('空')
        file1.close()
    #    print(cha(s1))
    
  • 相关阅读:
    AtCoder Beginner Contest 089 D
    AtCoder Beginner Contest 088 D Grid Repainting
    [odb-users] query results not being cached?
    cmake使用示例与整理总结
    CMake使用总结
    Create schema error (unknown database schema '')
    [odb-users] Create schema error (unknown database schema '')
    ODB(C++ ORM)用Mingw的完整编译过程
    odb_sqlite_demo
    ODB——基于c++的ORM映射框架尝试(使用)
  • 原文地址:https://www.cnblogs.com/NBeveryday/p/13257840.html
Copyright © 2020-2023  润新知