MetaQiu commited on
Commit ·
57152db
1
Parent(s): 7b7f906
feat
Browse files164 unmodified lines165166167168169170171172173174101 unmodified lines27627727827928028128284 unmodified lines367368369370371372373164 unmodified linesinfo["type"] = ret['net']return retdef get_ip_info(ip):info = get_maxmind(ip)if "country" in info and info["country"]["code"] == "CN" and ("registered_country" not in info or info["registered_country"]["code"] == "CN"):get_cn(ip, info)return infodef is_reserved_ip(ip: str) -> bool:101 unmodified linesclient_ip = client_ip.split(',')[0].strip()query_ip = ip.strip() if ip else client_ipresult = get_ip_info(query_ip)log_data = {"时间": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),"访问IP": client_ip,84 unmodified linesif client_ip and ',' in client_ip:client_ip = client_ip.split(',')[0].strip()result = get_ip_info(ip)log_data = {"时间": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),"访问IP": client_ip,164 unmodified lines165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199101 unmodified lines30130230330430530630784 unmodified lines392393394395396397398164 unmodified linesinfo["type"] = ret['net']return retasync def get_ip_info(ip):info = get_maxmind(ip)is_cn = "country" in info and info["country"]["code"] == "CN" and ("registered_country" not in info or info["registered_country"]["code"] == "CN")if is_cn:get_cn(ip, info)# 中国 IP 优先使用美团数据覆盖经纬度和地区,失败则保留本地数据库结果try:mt = await get_meituan_location(ip)if "error" not in mt:loc = mt.get("location", {})if loc.get("lat") and loc.get("lng"):info["location"] = {"latitude": loc["lat"],"longitude": loc["lng"]}regions = de_duplicate([loc.get("province", ""), loc.get("city", ""), loc.get("district", "")])if regions:info["regions"] = regionsinfo["regions_short"] = de_duplicate([province_match(loc.get("province", "")),loc.get("city", "").replace('市', ''),loc.get("district", "")])if loc.get("detail"):info["detail"] = loc["detail"]if loc.get("areaName"):info["areaName"] = loc["areaName"]except Exception:pass # 美团接口失败,保留 GeoCN 数据return infodef is_reserved_ip(ip: str) -> bool:101 unmodified linesclient_ip = client_ip.split(',')[0].strip()query_ip = ip.strip() if ip else client_ipresult = await get_ip_info(query_ip)log_data = {"时间": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),"访问IP": client_ip,84 unmodified linesif client_ip and ',' in client_ip:client_ip = client_ip.split(',')[0].strip()result = await get_ip_info(ip)log_data = {"时间": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),"访问IP": client_ip,
main.py+29-4