代码拉取完成,页面将自动刷新
import requests
import re
import os
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/993.0.4577.63 Safari/537.36'
}
def fetch_ips(url):
response = requests.get(url, headers=headers, timeout=3)
response.raise_for_status()
content = response.text
# 使用正则表达式提取IP地址
ips = re.findall(r'\b(?:\d{1,3}\.){3}\d{1,3}\b', content)
return ips
def write_to_file(filename, ips):
with open(filename, 'w') as f:
for ip in ips:
#f.write(f"Require not ip {ip}\n")
f.write("Require not ip {}\n".format(ip))
def main():
urls = [
'https://raw.githubusercontent.com/alienwaredream/denyip/main/wjwdenyip.txt',
'http://61.155.106.104:1234/teapot_badip.txt',
'https://www.binarydefense.com/banlist.txt',
'http://cinsscore.com/list/ci-badguys.txt',
'https://report.cs.rutgers.edu/DROP/attackers'
]
filename = 'teapot_badip.conf'
all_ips = []
for url in urls:
try:
ips = fetch_ips(url)
all_ips.extend(ips)
except (requests.RequestException, re.error) as e:
print(f"Error fetching IP addresses from {url}: {e}")
continue
# 去除重复的IP地址
all_ips = list(set(all_ips))
# 按照数字从小到大排序
all_ips.sort(key=lambda ip: [int(x) for x in ip.split('.')])
try:
write_to_file(filename, all_ips)
print(f"IP addresses written to {filename} successfully.")
os.system("sudo service apache2 graceful")
except IOError as e:
print(f"Error writing to {filename}: {e}")
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。