通过ip查地址的网站(教你查别人ip地址精确位置)

来源:国外服务器 在您之前已被浏览:1 次
导读:目前正在解读《通过ip查地址的网站(教你查别人ip地址精确位置)》的相关信息,《通过ip查地址的网站(教你查别人ip地址精确位置)》是由用户自行发布的知识型内容!下面请观看由(国外主机 - www.2bp.net)用户发布《通过ip查地址的网站(教你查别人ip地址精确位置)》的详细说明。
笨笨网美国主机,w ww.2 b p .n e t

在大数据时代,了解收集用户来源是必不可少的功能之一,本地搭建IP库进行IP分析是ELK日志分析功能的一部分,本文进行了工具拆解,将一步步教你搭建日志分析平台。

通过ip查地址的网站(教你查别人ip地址精确位置)

安装 geoip2 库

pip install geoip2 -i https://pypi.douban.com/simple

下载 Maxmind 网站的 IP 信息库

地址:
http://dev.maxmind.com/geoip/geoip2/geolite2

下载完之后,解压,将解压包中的 mmdb 文件复制到项目的应用程序中

本机使用的环境是python3.7.4

直接上代码

#!/usr/bin/python# -*-coding:utf-8-*-import geoip2.databasereader = geoip2.database.Reader('./GeoLite2-City.mmdb')# ip = input("输入你要查询的IP:n")response = reader.city('123.58.180.8') #网易ping www.163.com# response = reader.city(ip)# 有多种语言,我们这里主要输出英文和中文print(response.city.name)print("你查询的IP的地理位置是:")print("地区:{}({})".format(response.continent.names["es"], response.continent.names["zh-CN"]))print("国家:{}({}) ,简称:{}".format(response.country.name, response.country.names["zh-CN"], response.country.iso_code))print("洲/省:{}({})".format(response.subdivisions.most_specific.name, response.subdivisions.most_specific.names["zh-CN"]))print("城市:{}({})".format(response.city.name, response.city.names["zh-CN"]))print("经度:{},纬度{}".format(response.location.longitude, response.location.latitude))print("时区:{}".format(response.location.time_zone))print("邮编:{}".format(response.postal.code))

打印出结果

你查询的IP的地理位置是:地区:Asia(亚洲)国家:China(中国) ,简称:CN洲/省:Zhejiang(浙江省)城市:Hangzhou(杭州)经度:120.1619,纬度30.294时区:Asia/Shanghai邮编:None

2.至于在线库的使用是需要一个license_key

只有前面两步不太一样

连接: client = geoip2.webservice.Client(42, <license_key>)

查询 IP: response = client.insights(<IP>)

笨笨网美国主机,w ww.2 b p .n e t
提醒:《通过ip查地址的网站(教你查别人ip地址精确位置)》最后刷新时间 2025-03-21 11:19:26,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《通过ip查地址的网站(教你查别人ip地址精确位置)》该内容的真实性请自行鉴别。