diff --git a/IP_List_generator/README.md b/IP_List_generator/README.md new file mode 100644 index 0000000..1ad87e5 --- /dev/null +++ b/IP_List_generator/README.md @@ -0,0 +1,3 @@ +# IP List Generator + +todo \ No newline at end of file diff --git a/IP_List_generator/__init__.py b/IP_List_generator/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/IP_List_generator/ip_gen.py b/IP_List_generator/ip_gen.py new file mode 100644 index 0000000..b5b8e73 --- /dev/null +++ b/IP_List_generator/ip_gen.py @@ -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) \ No newline at end of file diff --git a/IP_List_generator/requirements.txt b/IP_List_generator/requirements.txt new file mode 100644 index 0000000..1f36e85 --- /dev/null +++ b/IP_List_generator/requirements.txt @@ -0,0 +1 @@ +pytz=2022.4 \ No newline at end of file