mirror of
https://github.com/minoplhy/scriptbox.git
synced 2024-12-04 17:36:57 +00:00
IP_List_generator : init
This commit is contained in:
parent
2cacfd7eff
commit
4c2d452ea9
3
IP_List_generator/README.md
Normal file
3
IP_List_generator/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# IP List Generator
|
||||
|
||||
todo
|
0
IP_List_generator/__init__.py
Normal file
0
IP_List_generator/__init__.py
Normal file
60
IP_List_generator/ip_gen.py
Normal file
60
IP_List_generator/ip_gen.py
Normal file
@ -0,0 +1,60 @@
|
||||
"""
|
||||
IP List Generator
|
||||
------------------
|
||||
|
||||
Currently, Input file must be in List format for example :
|
||||
|
||||
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
1.1.1.1
|
||||
1.0.0.1
|
||||
8.8.8.8
|
||||
2a07:e340::2
|
||||
2a10:50c0::ad2:ff
|
||||
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
"""
|
||||
import pytz
|
||||
import datetime
|
||||
|
||||
filters_set = tuple(["#","###","!"])
|
||||
|
||||
def caddy(listname, input, output):
|
||||
with open(input ,'r') as f:
|
||||
readinput = f.read().splitlines()
|
||||
with open(output, 'w') as f:
|
||||
f.write("# Caddy IP List Generated\n# Date Generated : " + BuildDate()+"\n#\n")
|
||||
f.write("@"+listname+" {\n")
|
||||
for line in readinput:
|
||||
if line.strip() and not line.startswith((filters_set)):
|
||||
f.write(" remote_ip " + line + "\n")
|
||||
else:
|
||||
pass
|
||||
f.write("}")
|
||||
|
||||
def nginx(input, output):
|
||||
with open(input ,'r') as f:
|
||||
readinput = f.read().splitlines()
|
||||
with open(output, 'w') as f:
|
||||
f.write("# Nginx IP List Generated\n# Date Generated : " + BuildDate()+"\n#\n")
|
||||
for line in readinput:
|
||||
if line.strip() and not line.startswith((filters_set)):
|
||||
f.write("deny " + line + ";\n")
|
||||
else:
|
||||
pass
|
||||
|
||||
def htaccess(input, output):
|
||||
with open(input ,'r') as f:
|
||||
readinput = f.read().splitlines()
|
||||
with open(output, 'w') as f:
|
||||
f.write("# htaccess IP List Generated\n# Date Generated : " + BuildDate()+"\n#\n")
|
||||
f.write("Order Deny,Allow\n")
|
||||
for line in readinput:
|
||||
if line.strip() and not line.startswith((filters_set)):
|
||||
f.write("Deny from " + line + "\n")
|
||||
else:
|
||||
pass
|
||||
|
||||
def BuildDate():
|
||||
UTC = pytz.utc
|
||||
date = datetime.datetime.now(UTC)
|
||||
return str(date)
|
1
IP_List_generator/requirements.txt
Normal file
1
IP_List_generator/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
pytz=2022.4
|
Loading…
Reference in New Issue
Block a user