工具 数据库

发布于 更新于

AI总结: 本文介绍了ip2region及其相关数据库的更新频率,包括ip2region-xdb的数据来自IP-API,GeoLite2数据库每三天更新,MaxMind的GeoLite2 Country、City和ASN数据库每月更新,geoip2-mirror每周更新,而GeoLite.mmdb则是每天更新。文中提供了一个Python示例,展示如何使用geoip2库从GeoLite2-Country.mmdb中获取IP地址的国家信息。没有明显的错误观点。

ip2region

ip2region-xdb 58M

数据来自IP-API

GeoLite2-Database 每3天更新

MaxMind's GeoLite2 Country, City, and ASN databases in csv and mmdb.

maxmind-geoip 每月12号更新

geoip2-mirror 每周二,五更新

GeoLite.mmdb 每天

import geoip2.database  

def get_ip_info(ip_address, db_path="GeoLite2-Country.mmdb"):  
    try:  
        with geoip2.database.Reader(db_path) as reader:  
            response = reader.country(ip_address)  
            return response.country.names.get('zh-CN', response.country.name)  
    except Exception as e:  
        print(f"GeoIP lookup failed for {ip_address}: {e}")  
        return ''  

# 使用示例  
ip_address = "8.8.8.8"  
country = get_ip_info(ip_address)  
print(f"Country: {country}")