Update server2.py
Browse files- server2.py +5 -6
server2.py
CHANGED
|
@@ -468,18 +468,17 @@ def replace_ip_and_country_in_file(file_path):
|
|
| 468 |
|
| 469 |
# 获取地理位置信息
|
| 470 |
geo_info = get_geo_info(ip_address)
|
|
|
|
| 471 |
|
| 472 |
if geo_info is not None:
|
| 473 |
-
print(f"获取到地理信息: {geo_info}")
|
| 474 |
-
|
| 475 |
# 读取文件内容
|
| 476 |
with open(file_path, 'r', encoding='utf-8') as file:
|
| 477 |
content = file.read()
|
| 478 |
# print(f"读取到的文件内容: {content}")
|
| 479 |
|
| 480 |
-
# 使用正则表达式匹配 "IP[xxx]国家[yyy]" 的格式
|
| 481 |
-
pattern = r'IP\[.*?\]
|
| 482 |
-
replacement = f'IP[{
|
| 483 |
new_content = re.sub(pattern, replacement, content)
|
| 484 |
|
| 485 |
# print(f"替换后的内容: {new_content}")
|
|
@@ -488,7 +487,7 @@ def replace_ip_and_country_in_file(file_path):
|
|
| 488 |
with open(file_path, 'w', encoding='utf-8') as file:
|
| 489 |
file.write(new_content)
|
| 490 |
|
| 491 |
-
print(f"成功更新为: IP[{
|
| 492 |
|
| 493 |
except FileNotFoundError:
|
| 494 |
print(f"错误: 文件 {file_path} 不存在。")
|
|
|
|
| 468 |
|
| 469 |
# 获取地理位置信息
|
| 470 |
geo_info = get_geo_info(ip_address)
|
| 471 |
+
print(f"获取到地理信息: {geo_info}")
|
| 472 |
|
| 473 |
if geo_info is not None:
|
|
|
|
|
|
|
| 474 |
# 读取文件内容
|
| 475 |
with open(file_path, 'r', encoding='utf-8') as file:
|
| 476 |
content = file.read()
|
| 477 |
# print(f"读取到的文件内容: {content}")
|
| 478 |
|
| 479 |
+
# 使用正则表达式匹配 "IP[xxx] 国家 [yyy] IPS[zzz]" 的格式
|
| 480 |
+
pattern = r'IP\[.*?\]\s*国家\s*\[.*?\]\s*IPS\[.*?\]'
|
| 481 |
+
replacement = f'IP[{ip_address}] 国家 [{geo_info["country"]}] IPS[{geo_info["isp"]}]'
|
| 482 |
new_content = re.sub(pattern, replacement, content)
|
| 483 |
|
| 484 |
# print(f"替换后的内容: {new_content}")
|
|
|
|
| 487 |
with open(file_path, 'w', encoding='utf-8') as file:
|
| 488 |
file.write(new_content)
|
| 489 |
|
| 490 |
+
print(f"成功更新为: IP[{ip_address}] 国家 [{geo_info['country']}] IPS[{geo_info['isp']}]")
|
| 491 |
|
| 492 |
except FileNotFoundError:
|
| 493 |
print(f"错误: 文件 {file_path} 不存在。")
|