python3.2批量查询IP地址区域

import urllib.request
#jk409  2014-7-31 by python3.4编写用于[批量]查询IP地址国家区域
def chaxun(ip_addr):
    ip_addr2=ip_addr
    domain_addr='http://ip.taobao.com/service/getIpInfo.php?ip='
    domain=domain_addr+ip_addr2
    res=urllib.request.urlopen(domain).read()
    page=eval(res)
    if page['code']==0:
        ww=page['data']['ip']+' '+page['data']['country_id']+' '+page['data']['country']+page['data']['region']+page['data']['city']
        '''
        print(
              page['data']['ip'],page['data']['country_id'],
              page['data']['country'],page['data']['region'],
              page['data']['city']
              )
              '''
        print(ww)
        wr_f.write(ww+'\n')  
    else:
        print('faile')

if __name__=="__main__":
    while 1:
        ip_addr = str(input('请输入要查询的IP:'))
        #if ip_addr == "quit":
        #    break;
        wr_f=open('c://2.log','w')
        f=open('c://2.txt','r')
        for a in f.readlines():
            chaxun(a.split()[0])
        f.close()
        wr_f.close()

python3.2批量查询IP地址区域

你可能感兴趣的:(查询IP,python查询IP地址区域)