Qilan2 commited on
Commit
e4138b6
·
verified ·
1 Parent(s): fd30477

Update server.py

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