Python之通过IP地址库获取IP地理信息
利用第三方的IP地址库,各个公司可以根据自己的业务情况打造自己的IP地址采集分析系统。例如游戏公司可以采集玩家地区信息,进行有针对性的运营策略,还可能帮助分析玩家网络故障分布等等。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import requests
import json
import argparse
import sys
def get_ip_info(ip):
# 淘宝IP地址库
url = "http://ip.taobao.com/service/getIpInfo.php?ip=%s" % ip
a = requests.get(url=url)
info = json.loads(a.text)
print(info, type(info))
print("IP:%s" % info["data"]["ip"])
print("国家:%s" % info["data"]['country'])
print("城市:%s" % info["data"]["city"])
print("地区:%s" % info["data"]["county"])
print("运营商:%s" % info["data"]["isp"])
print("运营商id:%s" % info["data"]["isp_id"]) if __name__ == "__main__":
parser = argparse.ArgumentParser(description="获取IP地址的地理信息")
args = parser.parse_args()
if len(sys.argv) == 1:
parser.print_help()
sys.exit()
while True:
inp = input("请输入要查询的IP地址(q退出):").strip()
if inp == "quit" or inp == "q":
break
get_ip_info(inp)
Python之通过IP地址库获取IP地理信息的更多相关文章
- 通过淘宝IP地址库获取IP位置
地址:http://ip.taobao.com/ 提供的服务包括: 1. 根据用户提供的IP地址,快速查询出该IP地址所在的地理信息和地理相关的信息,包括国家.省.市和运营商. 2. 用户可以根据自己 ...
- Jsp调用淘宝IP地址库获取来访IP详细信息
Jsp调用淘宝IP地址库获取来访IP详细信息 示例网页点击:www.trembler.cn/ipinfo/ipinfo(服务器有其他用处,页面已失效) String ip = request.ge ...
- 用淘宝ip地址库查ip
这是一个通过调用淘宝ip地址库实现ip地址查询的功能类 using System; using System.Collections.Generic; using System.Linq; using ...
- linux ip地址自动获取,ip地址…
linux ip地址自动获取,ip地址手动设置(图文解释) 2011-04-19 16:19:31| 分类: 服务器(appache/n | 标签: |字号大中小 订阅 linux ip地址自动获取( ...
- 通过新浪ip地址库获取用户省份
<script src="http://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js"></script> ...
- 淘宝IP地址库获取到省市IP地址
http://ip.aliyun.com/index.html https://ispip.clang.cn/ https://github.com/Pingze-github/local-ips 1 ...
- java通过请求对象获取ip地址、获取ip地址
/** * 获取登录ip */ public String getIp(){ HttpServletRequest request = this.getRequest(); String ip = & ...
- 利用纯真ip地址库 查询 ip所属地
1. 首先下周数据源,选择是纯真数据库:http://www.cz88.net/ 2. 安装后,打开软件,将数据导出为txt格式. 3. 处理数据,参照网上的文章(http://www.jb51.ne ...
- python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码
python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码 淘宝IP地址库 http://ip.taobao.com/目前提供的服务包括:1. 根据用户提供的 ...
随机推荐
- [LintCode] Paint House 粉刷房子
There are a row of n houses, each house can be painted with one of the three colors: red, blue or gr ...
- curl测试网页响应时间
连接时间: curl -s -o /dev/null -w "%{time_connect}\n" http://www.joinpay.com 传输时间: curl -s -o ...
- win10我能ping通他人,但他人ping不同我
这是防火墙的原因,关闭防火墙即可
- DG配置实验
1.配置主库环境 2.为备库创建备份文件 3.启动主备库验证配置 4.DG测试 5.DG主备库切换 6.DG主备库第二次切换
- 2016HUAS暑假集训训练题 F - 简单计算器
Description 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. Input 测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运 ...
- Web前端开发基础 第四课(CSS元素模型)
css布局模型 清楚了CSS 盒模型的基本概念. 盒模型类型, 我们就可以深入探讨网页布局的基本模型了.布局模型与盒模型一样都是 CSS 最基本. 最核心的概念. 但布局模型是建立在盒模型基础之上,又 ...
- 浅谈Service
一.生命周期: startService()方式启动,Service是通过接受Intent并且会经历onCreate()和onStart().当用户在发出意图使之销毁时会经历onDestroy():( ...
- 【iCore3 双核心板_FPGA】实验十五:基于USART的ARM与FPGA通信实验
实验指导书及代码包下载: http://pan.baidu.com/s/1c1RbE5E iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- ios-获取通讯录 姓名和电话
#import "ViewController.h" #import <ContactsUI/ContactsUI.h> @interface ViewControll ...
- faster with MyISAM tables than with InnoDB or NDB tables
http://dev.mysql.com/doc/refman/5.7/en/partitioning-limitations.html Performance considerations. So ...