API为国外API,频率限制1分钟45个ip

脚本如下

  1. 1 #!/usr/bin/env python3
  2. 2 #-*-coding:utf-8-*-
  3. 3
  4. 4 import requests,re,json,time,os
  5. 5
  6. 6 base_dir = os.path.dirname(os.path.abspath(__file__))
  7. 7 filename= base_dir + '/ipinfo'
  8. 8 with open(base_dir+'/ipaddress','r') as e:
  9. 9 ipaddress = e.read()
  10. 10 ip = json.loads(ipaddress)
  11. 11 ip_count = len(ip)
  12. 12 flag = 0
  13. 13 for x in ip:
  14. 14 r=requests.get('http://ip-api.com/json/%s'%x)
  15. 15 count = int(r.headers['X-Rl'])
  16. 16 ret = r.json()
  17. 17 info = {'ip':ret['query'],'country':ret['country'],'regionName':ret['regionName'],'city':ret['city'],'AS':ret['as']}
  18. 18
  19. 19 with open (filename,'a') as a:
  20. 20 a.write(json.dumps(info,ensure_ascii=False))
  21. 21 a.write('\n')
  22. 22 flag+=1
  23. 23 print('.'*flag,'%d%%'%int(flag/ip_count*100))
  24. 24 if count < 5:
  25. 25 print('the limit will run out please wite 60s')
  26. 26 time.sleep(60)

ipaddress文件为json格式

  1. ["103.219.22.126",
  2. "107.155.10.38",
  3. "107.155.16.239",
  4. "107.155.19.39",
  5. "108.61.123.142",
  6. "108.61.170.254",
  7. "108.61.196.36",
  8. "108.61.198.51",
  9. "128.1.55.57",
  10. "146.185.173.26",
  11. "151.80.238.250",
  12. "154.16.202.151",
  13. "172.247.36.37",
  14. "176.126.83.222",
  15. "185.137.181.144",
  16. "185.157.232.103",
  17. "185.175.56.111",
  18. "185.175.58.114"]

ipinfo文件也保存为json格式

  1. {"ip": "107.155.19.39", "country": "Spain", "regionName": "Madrid", "city": "Madrid", "AS": "AS21859 Zenlayer Inc"}
  2. {"ip": "108.61.123.142", "country": "France", "regionName": "Île-de-France", "city": "Paris", "AS": "AS20473 The Constant Company, LLC"}
  3. {"ip": "108.61.170.254", "country": "Germany", "regionName": "Hesse", "city": "Frankfurt am Main", "AS": "AS20473 The Constant Company, LLC"}
  4. {"ip": "108.61.196.36", "country": "United Kingdom", "regionName": "England", "city": "London", "AS": "AS20473 The Constant Company, LLC"}
  5. {"ip": "108.61.198.51", "country": "Netherlands", "regionName": "North Holland", "city": "Amsterdam", "AS": "AS20473 The Constant Company, LLC"}
  6. {"ip": "128.1.55.57", "country": "Russia", "regionName": "Moscow", "city": "Moscow", "AS": "AS21859 Zenlayer Inc"}
  7. {"ip": "146.185.173.26", "country": "Netherlands", "regionName": "North Holland", "city": "Amsterdam", "AS": "AS14061 DigitalOcean, LLC"}
  8. {"ip": "151.80.238.250", "country": "France", "regionName": "Hauts-de-France", "city": "Roubaix", "AS": "AS16276 OVH SAS"}
  9. {"ip": "154.16.202.151", "country": "Germany", "regionName": "Hesse", "city": "Frankfurt am Main", "AS": "AS61317 Digital Energy Technologies Ltd."}
  10. {"ip": "172.247.36.37", "country": "Germany", "regionName": "Hesse", "city": "Frankfurt am Main", "AS": "AS134176 Rainbow network limited"}
  11. {"ip": "176.126.83.222", "country": "Italy", "regionName": "Lombardy", "city": "Milan", "AS": "AS49367 Seflow S.N.C. Di Marco Brame' & C."}
  12. {"ip": "185.137.181.144", "country": "Bulgaria", "regionName": "Varna", "city": "Varna", "AS": "AS3170 Etheroute Ltd"}
  13. {"ip": "185.157.232.103", "country": "United Kingdom", "regionName": "England", "city": "Manchester", "AS": "AS46261 QuickPacket, LLC"}
  14. {"ip": "185.175.56.111", "country": "Norway", "regionName": "Oslo County", "city": "Oslo", "AS": "AS63473 HostHatch, LLC"}
  15. {"ip": "185.175.58.114", "country": "Austria", "regionName": "Vienna", "city": "Vienna", "AS": "AS63473 HostHatch, LLC"}

python 通过线上API查询ip归属地的更多相关文章

  1. [Ubuntu] geoip-bin 程序包 - 查询 IP 归属地

    简述:在Linux命令行下查询IP归属地. 对Ubuntu/Debian系统,使用APT命令进行安装: $ sudo apt-get install geoip-bin 该包由MaxMind提供,它同 ...

  2. 填坑!线上Presto查询Hudi表异常排查

    1. 引入 线上用户反馈使用Presto查询Hudi表出现错误,而将Hudi表的文件单独创建parquet类型表时查询无任何问题,关键报错信息如下 40931f6e-3422-4ffd-a692-6c ...

  3. 任何快速查询IP归属地

    最近公司项目需要做一个IP归属地查询的功能,想着如果用现成的API就可以大大提高开发效率,所以在网上的API商店搜索了一番,发现了 APISpace,它里面的IP归属地API非常符合我的开发需求.   ...

  4. Linux shell查询ip归属地

    起因 有的时候写脚本需要能够在脚本中获取到ip的归属地,比如分析登录日志列出攻击者的相关信息等. 可以使用whois来查询ip的详细信息,但是whois并不是每台机器预装的,而且我想看中文的结果,所以 ...

  5. python的线上环境配置

    1.安装python 2.7   http://www.cnblogs.com/strikebone/p/3970512.html 2.安装相关前置工具  pip, Django http://www ...

  6. python 利用cip.cc查询IP归属地

    def ipinfocip(ip): # 获得 输入框中的信息 url = "http://www.cip.cc/%s" % ip # 模拟浏览器请求网络 headers={'Us ...

  7. python 利用淘宝IP库 查询IP归属地

    #coding:utf-8 from django.test import TestCase import json import urllib ip = "114.114.114.114& ...

  8. 利用纯真ip地址库 查询 ip所属地

    1. 首先下周数据源,选择是纯真数据库:http://www.cz88.net/ 2. 安装后,打开软件,将数据导出为txt格式. 3. 处理数据,参照网上的文章(http://www.jb51.ne ...

  9. JS 新浪API获取IP归属地

    http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 返回值数据格式:var remote_ip_info = {“ret”:1,” ...

随机推荐

  1. Python - Python函数简介

  2. 使用缓存(Cache)的几种方式,回顾一下~~~

    前言 如今缓存成为了优化网站性能的首要利器,缓存使用的好,不仅能让网站性能提升,让用户体验变好,而且还能节约成本(增加一台缓存服务器可能就节约好几台机器):那平时小伙伴们都使用哪些缓存方式呢?这里就来 ...

  3. CPU架构:CPU架构详细介绍

    1 概述 CPU架构是CPU商给CPU产品定的一个规范,主要目的是为了区分不同类型的CPU.目前市场上的CPU分类主要分有两大阵营,一个是intel.AMD为首的复杂指令集CPU,另一个是以IBM.A ...

  4. vue和mint-ui loadMore 实现上拉加载和下拉刷新

    首先安装mint-ui组件库 npm install mint-ui 在main.js中引入mint-ui和样式 import 'mint-ui/lib/style.css' import MintU ...

  5. 项目需求与分析--NABCD模型

    合作项目特点NABCD分析结果: 特点:便捷 N(Need 需求):在大学期间内,我们通常会有许多不用的课本或书籍或者其他东西,堆积起来又没有地方放,想卖出去就要建一个群,十分麻烦,开发该软件用户可直 ...

  6. 嵌入式框架iframe

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. vue-cropper裁剪上传

    效果图: 全部代码: npm install vue-cropper //首先 安装vue-cropper main.js全局引用: import VueCropper from 'vue-cropp ...

  8. 微信小程序超出后...

    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;

  9. git-flow-avh的使用过程

    安装: 在mac上 brew install git-flow-avh 使用: 在仓库中 git flow init 一路回车就行,这个命令相当于写入一些默认命令流程到.git中, 此命令执行之后会增 ...

  10. 为Anaconda python3安装gi模块

    项目开发中需要使用到gi模块,Ubuntu自带的Python3.5可以正常使用gi.项目解释环境是Anaconda python3.5,提示ImportError: No module named ' ...