利用Python geoip2模块关联ip地址和物理位置(经纬度)

32 篇文章 1 订阅
27 篇文章 0 订阅

Python geoip2模块关联ip地址和物理位置(经纬度)

注意:在运行代码之前,需要先下载GeoLite2-City.mmdb这个配套的数据库,如果下载有问题的,可以直接去我的资源里下载,我已将资源上传

import geoip2.database

reader = geoip2.database.Reader(
    'GeoLite2-City.mmdb')


def ip_print_AddrInfo(ip):
    response = reader.city(ip)
    Country_IsoCode = response.country.iso_code
    Country_Name = response.country.name
    Country_NameCN = response.country.names['zh-CN']
    City_PostalCode = response.postal.code
    Location_Latitude = response.location.latitude
    Location_Longitude = response.location.longitude
    
    print('[*] Target: ' + ip + ' GeoLite2-Located ')
    print('  [+] Country_IsoCode        : ' + Country_IsoCode)
    print('  [+] Country_Name           : ' + Country_Name)
    print('  [+] Country_NameCN         : ' + Country_NameCN)
    if City_PostalCode is not None:
        print('  [+] City_PostalCode        : ' + City_PostalCode)
    print('  [+] Location_Latitude      : ' + str(Location_Latitude))
    print('  [+] Location_Longitude     : ' + str(Location_Longitude))


ip = '218.58.101.229'	//将ip地址改为你想要查找的地址,这里我用的是苹果网站的地址
ip_print_AddrInfo(ip)
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值