From 4c2d452ea9b3713c236a9f8079825f3b9017fd1b Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 2 Oct 2022 19:35:37 +0700 Subject: [PATCH] IP_List_generator : init --- IP_List_generator/README.md | 3 ++ IP_List_generator/__init__.py | 0 IP_List_generator/ip_gen.py | 60 ++++++++++++++++++++++++++++++ IP_List_generator/requirements.txt | 1 + 4 files changed, 64 insertions(+) create mode 100644 IP_List_generator/README.md create mode 100644 IP_List_generator/__init__.py create mode 100644 IP_List_generator/ip_gen.py create mode 100644 IP_List_generator/requirements.txt 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