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

脚本如下

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

ipaddress文件为json格式

["103.219.22.126",
"107.155.10.38",
"107.155.16.239",
"107.155.19.39",
"108.61.123.142",
"108.61.170.254",
"108.61.196.36",
"108.61.198.51",
"128.1.55.57",
"146.185.173.26",
"151.80.238.250",
"154.16.202.151",
"172.247.36.37",
"176.126.83.222",
"185.137.181.144",
"185.157.232.103",
"185.175.56.111",
"185.175.58.114"]

ipinfo文件也保存为json格式

{"ip": "107.155.19.39", "country": "Spain", "regionName": "Madrid", "city": "Madrid", "AS": "AS21859 Zenlayer Inc"}
{"ip": "108.61.123.142", "country": "France", "regionName": "Île-de-France", "city": "Paris", "AS": "AS20473 The Constant Company, LLC"}
{"ip": "108.61.170.254", "country": "Germany", "regionName": "Hesse", "city": "Frankfurt am Main", "AS": "AS20473 The Constant Company, LLC"}
{"ip": "108.61.196.36", "country": "United Kingdom", "regionName": "England", "city": "London", "AS": "AS20473 The Constant Company, LLC"}
{"ip": "108.61.198.51", "country": "Netherlands", "regionName": "North Holland", "city": "Amsterdam", "AS": "AS20473 The Constant Company, LLC"}
{"ip": "128.1.55.57", "country": "Russia", "regionName": "Moscow", "city": "Moscow", "AS": "AS21859 Zenlayer Inc"}
{"ip": "146.185.173.26", "country": "Netherlands", "regionName": "North Holland", "city": "Amsterdam", "AS": "AS14061 DigitalOcean, LLC"}
{"ip": "151.80.238.250", "country": "France", "regionName": "Hauts-de-France", "city": "Roubaix", "AS": "AS16276 OVH SAS"}
{"ip": "154.16.202.151", "country": "Germany", "regionName": "Hesse", "city": "Frankfurt am Main", "AS": "AS61317 Digital Energy Technologies Ltd."}
{"ip": "172.247.36.37", "country": "Germany", "regionName": "Hesse", "city": "Frankfurt am Main", "AS": "AS134176 Rainbow network limited"}
{"ip": "176.126.83.222", "country": "Italy", "regionName": "Lombardy", "city": "Milan", "AS": "AS49367 Seflow S.N.C. Di Marco Brame' & C."}
{"ip": "185.137.181.144", "country": "Bulgaria", "regionName": "Varna", "city": "Varna", "AS": "AS3170 Etheroute Ltd"}
{"ip": "185.157.232.103", "country": "United Kingdom", "regionName": "England", "city": "Manchester", "AS": "AS46261 QuickPacket, LLC"}
{"ip": "185.175.56.111", "country": "Norway", "regionName": "Oslo County", "city": "Oslo", "AS": "AS63473 HostHatch, LLC"}
{"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. 记录md的偏好设置

  2. Azure DevOps (八) 通过流水线编译Docker镜像

    上一篇文章我们完成了最简单的传统部署:上传应用到服务器上使用守护进程进行应用的部署. 本篇文章我们开始研究容器化和流水线的协作. 在开始操作之前,我们首先需要准备一下我们的dockerfile,这里我 ...

  3. 【精】多层PCB层叠结构

    在设计多层PCB电路板之前,设计者需要首先根据电路的规模.电路板的尺寸和电磁兼容(EMC)的要求来确定所采用的电路板结构,也就是决定采用4层,6层,还是更多层数的电路板.确定层数之后,再确定内电层的放 ...

  4. CSS 3-浮动、定位

    文档流 文档流是一种默认定位方式,在文档流中元素框的位置由元素在html中的位置决定,文档流中元素的position属性为默认的static或继承来的static并按照普通流定位.块级元素独占一行,自 ...

  5. css3 弹性布局和多列布局

    弹性盒子基础 弹性盒子(Flexible Box)是css3中盒子模型的弹性布局,在传统的布局方式上增加了很多灵活性. 定义一个弹性盒子 在父盒子上定义display属性: #box{ display ...

  6. 富文本编辑器CKeditor的配置和图片上传,看完不后悔

    CKeditor是一款富文本编辑器,本文将用极为简单的方式介绍一下它的使用和困扰大家很久的图片上传问题,要有耐心. 第一步:如何使用 1.官网下载https://ckeditor.com/ckedit ...

  7. 手机上无法显示Toast信息

    关于手机上无法显示Toast信息, 是因为手机上的权限没有开, 在应用管理处将所有权限都打开,就可以显示了.

  8. 【uniapp 开发】uni-app 技术点的链接记录

    优雅的H5下拉刷新.零依赖,高性能,多主题,易拓展 https://ask.dcloud.net.cn/article/12772 图像(头像)选择,截取,压缩,上传的分享 https://ask.d ...

  9. MySQL数据库设置编码格式和时区

    MySQL数据库设置编码格式和时区 MySQL5版本: url=jdbc:mysql://localhost:3306/test?characterEncoding=utf-8 MySQL6版本及以上 ...

  10. spring-注入list集合对象(值是对象)

    1.创建stu类 public class Stu { // //1.数组类型 // private String[] courses; // // //2.list集合属性 // private L ...