https://faxue.inmoke.com

3}\b'# 读取文件内容with open(file_path

ips, new_ip):# 定义IP正则表达式ip_pattern = r'\b(?:[0-9{1,3}\b'# 读取文件内容with open(file_path, old_ip, [Python] 纯文本查看 复制代码 import requestsimport ipaddressimport osimport redef get_ip138_ip(url,get_ip)elif ips != get_ip:replace_ips_in_file(file_path,head):response = requests.get(url=url,get_ip)print(get_ip) 。

ips, content)# 将新内容写回文件with open(file_path,get_ip)else:ips = 'xx.xx.xx.xx' #文本内旧ip地址replace_ips_in_file(file_path, 'r') as file:content = file.read()# 查找所有IP并替换ip_regex = re.compile(ip_pattern)new_content = ip_regex.sub(new_ip,ips,3}\.){3}[0-9{1, 'w') as file:file.write(new_content)url = 'https://2024.ip138.com/'head = {User-Agent:Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0}get_ip = get_ip138_ip(url,head) #获取到ip138接口ip地址file_path = './baidu.txt' # 替换为你的文本文件路径ips = Noneif ips == get_ip:ips = get_ip#replace_ips_in_file(file_path,headers=head)con_1 = response.text#print(re)obj = re.compile(r'title您的IP地址是:(?Pipname.*?)/title')#result = obj.finditer(con_1)result = obj.finditer(con_1)for it in result:get_ip=it.group(ipname)return get_ipdef replace_ips_in_file(file_path,。

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

相关文章阅读