3 Star 0 Fork 1

mithrill/baniplist

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
get_deny_ip_list.py 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
mithrill 提交于 2023-09-16 21:36 +08:00 . 获取IP列表,加入Nginx配置
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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mithrill/BlockingIPAddresses.git
git@gitee.com:mithrill/BlockingIPAddresses.git
mithrill
BlockingIPAddresses
baniplist
master

搜索帮助