Update main.py
Browse files
main.py
CHANGED
@@ -135,7 +135,6 @@ def get_addr(ip, mask):
|
|
135 |
network = ipaddress.ip_network(f"{ip}/{mask}", strict=False)
|
136 |
first_ip = network.network_address
|
137 |
return f"{first_ip}/{mask}"
|
138 |
-
|
139 |
def get_maxmind(ip: str):
|
140 |
ret = {"ip":ip}
|
141 |
asn_info = asn_reader.get(ip)
|
@@ -154,35 +153,64 @@ def get_maxmind(ip: str):
|
|
154 |
# 添加经纬度和时区信息
|
155 |
if "location" in city_info:
|
156 |
location = city_info["location"]
|
157 |
-
|
158 |
-
|
159 |
-
"
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
162 |
|
163 |
# 添加大洲信息
|
164 |
-
if "continent" in city_info:
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
169 |
|
170 |
# 添加邮政编码
|
171 |
-
if "postal" in city_info:
|
172 |
-
|
|
|
|
|
173 |
|
174 |
# 添加网络特征
|
175 |
-
if "traits" in city_info:
|
176 |
traits = city_info["traits"]
|
177 |
-
|
178 |
-
|
179 |
-
"
|
180 |
-
|
|
|
|
|
|
|
181 |
|
182 |
if "country" in city_info:
|
183 |
country_code = city_info["country"]["iso_code"]
|
184 |
country_name = get_country(city_info["country"])
|
185 |
ret["country"] = {"code":country_code,"name":country_name}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
def get_cn(ip:str, info={}):
|
188 |
ret, prefix = cn_reader.get_with_prefix_len(ip)
|
|
|
135 |
network = ipaddress.ip_network(f"{ip}/{mask}", strict=False)
|
136 |
first_ip = network.network_address
|
137 |
return f"{first_ip}/{mask}"
|
|
|
138 |
def get_maxmind(ip: str):
|
139 |
ret = {"ip":ip}
|
140 |
asn_info = asn_reader.get(ip)
|
|
|
153 |
# 添加经纬度和时区信息
|
154 |
if "location" in city_info:
|
155 |
location = city_info["location"]
|
156 |
+
loc_data = {}
|
157 |
+
if "latitude" in location:
|
158 |
+
loc_data["latitude"] = location["latitude"]
|
159 |
+
if "longitude" in location:
|
160 |
+
loc_data["longitude"] = location["longitude"]
|
161 |
+
if "time_zone" in location:
|
162 |
+
loc_data["timezone"] = location["time_zone"]
|
163 |
+
if loc_data:
|
164 |
+
ret["location"] = loc_data
|
165 |
|
166 |
# 添加大洲信息
|
167 |
+
if "continent" in city_info and city_info["continent"]:
|
168 |
+
try:
|
169 |
+
ret["continent"] = {
|
170 |
+
"code": city_info["continent"].get("code"),
|
171 |
+
"name": get_des(city_info["continent"]) if "names" in city_info["continent"] else None
|
172 |
+
}
|
173 |
+
except Exception:
|
174 |
+
pass
|
175 |
|
176 |
# 添加邮政编码
|
177 |
+
if "postal" in city_info and city_info["postal"]:
|
178 |
+
postal_code = city_info["postal"].get("code")
|
179 |
+
if postal_code:
|
180 |
+
ret["postal"] = postal_code
|
181 |
|
182 |
# 添加网络特征
|
183 |
+
if "traits" in city_info and city_info["traits"]:
|
184 |
traits = city_info["traits"]
|
185 |
+
traits_data = {}
|
186 |
+
if "is_anonymous_proxy" in traits:
|
187 |
+
traits_data["is_anonymous_proxy"] = traits["is_anonymous_proxy"]
|
188 |
+
if "is_satellite_provider" in traits:
|
189 |
+
traits_data["is_satellite_provider"] = traits["is_satellite_provider"]
|
190 |
+
if traits_data:
|
191 |
+
ret["traits"] = traits_data
|
192 |
|
193 |
if "country" in city_info:
|
194 |
country_code = city_info["country"]["iso_code"]
|
195 |
country_name = get_country(city_info["country"])
|
196 |
ret["country"] = {"code":country_code,"name":country_name}
|
197 |
+
|
198 |
+
if "registered_country" in city_info:
|
199 |
+
registered_country_code = city_info["registered_country"]["iso_code"]
|
200 |
+
ret["registered_country"] = {"code":registered_country_code,"name":get_country(city_info["registered_country"])}
|
201 |
+
|
202 |
+
regions = [get_des(i) for i in city_info.get('subdivisions', [])]
|
203 |
+
|
204 |
+
if "city" in city_info:
|
205 |
+
c = get_des(city_info["city"])
|
206 |
+
if (not regions or c not in regions[-1])and c not in country_name:
|
207 |
+
regions.append(c)
|
208 |
+
|
209 |
+
regions = de_duplicate(regions)
|
210 |
+
if regions:
|
211 |
+
ret["regions"] = regions
|
212 |
+
|
213 |
+
return ret
|
214 |
|
215 |
def get_cn(ip:str, info={}):
|
216 |
ret, prefix = cn_reader.get_with_prefix_len(ip)
|