python 通过线上API查询ip归属地
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归属地的更多相关文章
- [Ubuntu] geoip-bin 程序包 - 查询 IP 归属地
简述:在Linux命令行下查询IP归属地. 对Ubuntu/Debian系统,使用APT命令进行安装: $ sudo apt-get install geoip-bin 该包由MaxMind提供,它同 ...
- 填坑!线上Presto查询Hudi表异常排查
1. 引入 线上用户反馈使用Presto查询Hudi表出现错误,而将Hudi表的文件单独创建parquet类型表时查询无任何问题,关键报错信息如下 40931f6e-3422-4ffd-a692-6c ...
- 任何快速查询IP归属地
最近公司项目需要做一个IP归属地查询的功能,想着如果用现成的API就可以大大提高开发效率,所以在网上的API商店搜索了一番,发现了 APISpace,它里面的IP归属地API非常符合我的开发需求. ...
- Linux shell查询ip归属地
起因 有的时候写脚本需要能够在脚本中获取到ip的归属地,比如分析登录日志列出攻击者的相关信息等. 可以使用whois来查询ip的详细信息,但是whois并不是每台机器预装的,而且我想看中文的结果,所以 ...
- python的线上环境配置
1.安装python 2.7 http://www.cnblogs.com/strikebone/p/3970512.html 2.安装相关前置工具 pip, Django http://www ...
- python 利用cip.cc查询IP归属地
def ipinfocip(ip): # 获得 输入框中的信息 url = "http://www.cip.cc/%s" % ip # 模拟浏览器请求网络 headers={'Us ...
- python 利用淘宝IP库 查询IP归属地
#coding:utf-8 from django.test import TestCase import json import urllib ip = "114.114.114.114& ...
- 利用纯真ip地址库 查询 ip所属地
1. 首先下周数据源,选择是纯真数据库:http://www.cz88.net/ 2. 安装后,打开软件,将数据导出为txt格式. 3. 处理数据,参照网上的文章(http://www.jb51.ne ...
- JS 新浪API获取IP归属地
http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 返回值数据格式:var remote_ip_info = {“ret”:1,” ...
随机推荐
- Effective Java —— 避免创建不必要的对象
本文参考 本篇文章参考自<Effective Java>第三版第六条"Avoid creating unnecessary objects" avoid creatin ...
- 【精】多层PCB层叠结构
在设计多层PCB电路板之前,设计者需要首先根据电路的规模.电路板的尺寸和电磁兼容(EMC)的要求来确定所采用的电路板结构,也就是决定采用4层,6层,还是更多层数的电路板.确定层数之后,再确定内电层的放 ...
- Altium Designer PCB文件的绘制(下:PCB布线和检查)
在完成电路板的布局工作后,就可以开始布线操作了.在PCB的设计中,布线是完成产品设计的最重要的步骤,其要求最高.技术最细.工作量最大.PCB布线可分为单面布线.双面布线.多层布线.布线的方式有自动布线 ...
- keil Uvision4 面向51单片机数据类型属性一览表
- jsp+servlet上传excel并将数据导入到数据库表的实现方法
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 微信h5静默和非静默授权获取用户openId和用户信息的方法和步骤:
原文链接:https://blog.csdn.net/qq_35430000/article/details/79299529 一.openId是什么?openId是用户在当前公众号下的唯一标识('身 ...
- [ Skill ] 为什么 Lisp 语言如此先进
https://www.cnblogs.com/yeungchie/ 网上看到一个应该是 2002 年的文章 译文转自:为什么Lisp语言如此先进?(译文) - 阮一峰的网络日志 原文地址:Reven ...
- SSM实现个人博客-day01
1.需求分析 项目源码免费下载:SSM实现个人博客 有问题请询问vx:kht808
- ip地址后面斜杠加数字的含义
案例如:10.121.246.8/29 1.概念: 首先这是一种划分ip的表示方式,叫做无分类域间路由选择(CIDR),区分于传统的划分ip方式(分类的ip划分,在这之后提出了划分子网,即将主机号借出 ...
- 想减少代码量,快设置一个有感知的 Aware Spring Bean
摘要:正常情况下,Spring 中的 Bean 对 Spring 是无感知的,Spring 框架提供了这种扩展能力,能让一个 bean 成为有感知的. 本文分享自华为云社区<有感知的 Aware ...