From 69e5683dd7d96b85eae2babfea2bc8c918f7cd1a Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:54:52 +0300 Subject: [PATCH 01/40] Create blacklistipchecker.py --- other/blacklistipchecker.py | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 other/blacklistipchecker.py diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py new file mode 100644 index 000000000000..952215ea94e8 --- /dev/null +++ b/other/blacklistipchecker.py @@ -0,0 +1,101 @@ +###################################### +# This CLI script checks if entered ips are or aren`t blacklisted on different lists +# After configuration it can even send an email report +# You need to get API key on blacklistchecker to make it work (it`s free 30 IPs per month) +###################################### + + +import requests +import sys +from IPy import IP +import smtplib +from email.message import EmailMessage +import json + +API_key = '' +subject = '' +from = '' +to = '' +smtp_user = '' +smtp_passw = '' +smtp_serv = '' +smtp_port = 587 + +def test_ip(ip): + detects = [] + result = requests.get('https://api.blacklistchecker.com/check/'+ip, auth=(API_Key,'')) + result_dec = json.loads(result.content) + print(result_dec) + if result_dec.get('statusCode'): + res="limit exceeded" + detects = "!" + return(res, detects) + elif result_dec.get('detections') != 0: + res = ip + blsts = result_dec.get('blacklists') + for n in blsts: + if n.get('detected') == True: + detects.append(n.get('name')) + return(res, detects) + else: + return() + +res_txt = 'IP blacklists check returned next results:\n' +send_param = 0 +if len(sys.argv) > 1: + for x in sys.argv[1:]: + if x in '-y-Y': + send_param = 1 + else: + try: + IP(x) + except: + print('Argument isn`t a valid ip('+x+")\n Skipping argument") + else: + if test_ip(x): + res, detec = test_ip(x) + if res == "limit exceeded": + res_txt = res_txt +" LIMIT Exceeded!" + break + else: + res_txt = res_txt + str(res) +' is detected in '+ str(detec) +' blacklists \n \n' +else: + print('Type in ip to check') + x = input() + try: + IP(x) + except: + print('Argument isn`t a valid ip('+x+")") + sys.exit() + else: + if test_ip(x): + res, detec = test_ip(x) + if res == "limit exceeded": + res_txt = res_txt + "Limit Exceeded!\n" + else: + res_txt = res_txt + str(res) +' is detected in '+ str(detec) +' blacklists \n \n' +if len(res_txt) <= 43: + print("IPs not blacklisted!") + print(res_txt) +else: + if send_param == 1: + mailed = "Y" + else: + print('Send e-mail report? (default No)') + mailed = input() + if mailed in 'Yy' and mailed != "": + msg = EmailMessage() + msg.set_content(res_txt) + msg['Subject'] = subject + msg['From'] = from + msg['To'] = to + try: + smtp_server = smtplib.SMTP(smtp_server, smtp_port) + smtp_server.ehlo() + smtp_server.login(smtp_user, smtp_passw) + smtp_server.send_message(msg) + smtp_server.close() + print ("Email sent successfully to "+msg['to']+"!") + except Exception as ex: + print ("Something went wrong! ¦.",ex) + print('Blacklist check result is: \n' + res_txt) From c66872c48ea6da3dbbcfe39149f435f66361b3cb Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 2 Oct 2023 07:55:05 +0000 Subject: [PATCH 02/40] updating DIRECTORY.md --- DIRECTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 7d3ceee144be..4f862c5beb1d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -233,6 +233,7 @@ * [Merge Two Lists](data_structures/linked_list/merge_two_lists.py) * [Middle Element Of Linked List](data_structures/linked_list/middle_element_of_linked_list.py) * [Print Reverse](data_structures/linked_list/print_reverse.py) + * [Reverse K Group](data_structures/linked_list/reverse_k_group.py) * [Rotate To The Right](data_structures/linked_list/rotate_to_the_right.py) * [Singly Linked List](data_structures/linked_list/singly_linked_list.py) * [Skip List](data_structures/linked_list/skip_list.py) @@ -727,6 +728,7 @@ ## Other * [Activity Selection](other/activity_selection.py) * [Alternative List Arrange](other/alternative_list_arrange.py) + * [Blacklistipchecker](other/blacklistipchecker.py) * [Davisb Putnamb Logemannb Loveland](other/davisb_putnamb_logemannb_loveland.py) * [Dijkstra Bankers Algorithm](other/dijkstra_bankers_algorithm.py) * [Doomsday](other/doomsday.py) From 7cf1665eb0a758e33d19f1f5bd746b62899accf1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 07:55:48 +0000 Subject: [PATCH 03/40] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/blacklistipchecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 952215ea94e8..fc248f48e00a 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -59,7 +59,7 @@ def test_ip(ip): break else: res_txt = res_txt + str(res) +' is detected in '+ str(detec) +' blacklists \n \n' -else: +else: print('Type in ip to check') x = input() try: From fbf9f42fdbb098b39f1860f3a2bebbd34ab99b5f Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:10:16 +0300 Subject: [PATCH 04/40] Update blacklistipchecker.py added logging for exceptions, fixed invalid var name, --- other/blacklistipchecker.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index fc248f48e00a..dc0a44eda34b 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -11,11 +11,12 @@ import smtplib from email.message import EmailMessage import json +import logging API_key = '' subject = '' -from = '' -to = '' +mail_from = '' +mail_to = '' smtp_user = '' smtp_passw = '' smtp_serv = '' @@ -49,8 +50,9 @@ def test_ip(ip): else: try: IP(x) - except: + except Exception as ex: print('Argument isn`t a valid ip('+x+")\n Skipping argument") + logging.exception('Caught an error') else: if test_ip(x): res, detec = test_ip(x) @@ -64,8 +66,9 @@ def test_ip(ip): x = input() try: IP(x) - except: + except Exception as ex: print('Argument isn`t a valid ip('+x+")") + logging.exception('Caught an error') sys.exit() else: if test_ip(x): @@ -87,8 +90,8 @@ def test_ip(ip): msg = EmailMessage() msg.set_content(res_txt) msg['Subject'] = subject - msg['From'] = from - msg['To'] = to + msg['From'] = mail_from + msg['To'] = mail_to try: smtp_server = smtplib.SMTP(smtp_server, smtp_port) smtp_server.ehlo() From 83e70364d9e01626730d936226cad2e4bae8e3d7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 09:11:48 +0000 Subject: [PATCH 05/40] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/blacklistipchecker.py | 94 ++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index dc0a44eda34b..2614bd9abe76 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -13,70 +13,86 @@ import json import logging -API_key = '' -subject = '' -mail_from = '' -mail_to = '' -smtp_user = '' -smtp_passw = '' -smtp_serv = '' +API_key = "" +subject = "" +mail_from = "" +mail_to = "" +smtp_user = "" +smtp_passw = "" +smtp_serv = "" smtp_port = 587 + def test_ip(ip): detects = [] - result = requests.get('https://api.blacklistchecker.com/check/'+ip, auth=(API_Key,'')) + result = requests.get( + "https://api.blacklistchecker.com/check/" + ip, auth=(API_Key, "") + ) result_dec = json.loads(result.content) print(result_dec) - if result_dec.get('statusCode'): - res="limit exceeded" + if result_dec.get("statusCode"): + res = "limit exceeded" detects = "!" - return(res, detects) - elif result_dec.get('detections') != 0: + return (res, detects) + elif result_dec.get("detections") != 0: res = ip - blsts = result_dec.get('blacklists') + blsts = result_dec.get("blacklists") for n in blsts: - if n.get('detected') == True: - detects.append(n.get('name')) - return(res, detects) + if n.get("detected") == True: + detects.append(n.get("name")) + return (res, detects) else: - return() + return () + -res_txt = 'IP blacklists check returned next results:\n' +res_txt = "IP blacklists check returned next results:\n" send_param = 0 if len(sys.argv) > 1: for x in sys.argv[1:]: - if x in '-y-Y': + if x in "-y-Y": send_param = 1 else: try: IP(x) except Exception as ex: - print('Argument isn`t a valid ip('+x+")\n Skipping argument") - logging.exception('Caught an error') + print("Argument isn`t a valid ip(" + x + ")\n Skipping argument") + logging.exception("Caught an error") else: if test_ip(x): res, detec = test_ip(x) if res == "limit exceeded": - res_txt = res_txt +" LIMIT Exceeded!" + res_txt = res_txt + " LIMIT Exceeded!" break else: - res_txt = res_txt + str(res) +' is detected in '+ str(detec) +' blacklists \n \n' + res_txt = ( + res_txt + + str(res) + + " is detected in " + + str(detec) + + " blacklists \n \n" + ) else: - print('Type in ip to check') + print("Type in ip to check") x = input() try: IP(x) except Exception as ex: - print('Argument isn`t a valid ip('+x+")") - logging.exception('Caught an error') + print("Argument isn`t a valid ip(" + x + ")") + logging.exception("Caught an error") sys.exit() else: if test_ip(x): - res, detec = test_ip(x) - if res == "limit exceeded": - res_txt = res_txt + "Limit Exceeded!\n" - else: - res_txt = res_txt + str(res) +' is detected in '+ str(detec) +' blacklists \n \n' + res, detec = test_ip(x) + if res == "limit exceeded": + res_txt = res_txt + "Limit Exceeded!\n" + else: + res_txt = ( + res_txt + + str(res) + + " is detected in " + + str(detec) + + " blacklists \n \n" + ) if len(res_txt) <= 43: print("IPs not blacklisted!") print(res_txt) @@ -84,21 +100,21 @@ def test_ip(ip): if send_param == 1: mailed = "Y" else: - print('Send e-mail report? (default No)') + print("Send e-mail report? (default No)") mailed = input() - if mailed in 'Yy' and mailed != "": + if mailed in "Yy" and mailed != "": msg = EmailMessage() msg.set_content(res_txt) - msg['Subject'] = subject - msg['From'] = mail_from - msg['To'] = mail_to + msg["Subject"] = subject + msg["From"] = mail_from + msg["To"] = mail_to try: smtp_server = smtplib.SMTP(smtp_server, smtp_port) smtp_server.ehlo() smtp_server.login(smtp_user, smtp_passw) smtp_server.send_message(msg) smtp_server.close() - print ("Email sent successfully to "+msg['to']+"!") + print("Email sent successfully to " + msg["to"] + "!") except Exception as ex: - print ("Something went wrong! ¦.",ex) - print('Blacklist check result is: \n' + res_txt) + print("Something went wrong! ¦.", ex) + print("Blacklist check result is: \n" + res_txt) From 283e6334b5bb200009eb54a86e7939ed55652f1f Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:18:36 +0300 Subject: [PATCH 06/40] Update blacklistipchecker.py added type-hints, fixed var name --- other/blacklistipchecker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 2614bd9abe76..2f0912d433fe 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -13,7 +13,7 @@ import json import logging -API_key = "" +api_key = "" subject = "" mail_from = "" mail_to = "" @@ -23,10 +23,10 @@ smtp_port = 587 -def test_ip(ip): +def test_ip(ip: str) -> str, str | None: detects = [] result = requests.get( - "https://api.blacklistchecker.com/check/" + ip, auth=(API_Key, "") + "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") ) result_dec = json.loads(result.content) print(result_dec) From 616c1db8edd29b6e1d937d1b26ef9f139b250381 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:20:39 +0300 Subject: [PATCH 07/40] Update blacklistipchecker.py Fixed type hint --- other/blacklistipchecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 2f0912d433fe..6ec3efc5ae84 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -23,7 +23,7 @@ smtp_port = 587 -def test_ip(ip: str) -> str, str | None: +def test_ip(ip: str) -> Tuple[str, str] | None: detects = [] result = requests.get( "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") From d10e27155e7eb2c3eba2f837ad1665f40063396a Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:35:04 +0300 Subject: [PATCH 08/40] Update blacklistipchecker.py Fixed type hints, and list creation err --- other/blacklistipchecker.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 6ec3efc5ae84..f0466f20e043 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -1,7 +1,9 @@ ###################################### -# This CLI script checks if entered ips are or aren`t blacklisted on different lists +# This CLI script checks if entered ips are or +# aren`t blacklisted on different lists # After configuration it can even send an email report -# You need to get API key on blacklistchecker to make it work (it`s free 30 IPs per month) +# You need to get API key on blacklistchecker +# to make it work (it`s free 30 IPs per month) ###################################### @@ -22,9 +24,7 @@ smtp_serv = "" smtp_port = 587 - -def test_ip(ip: str) -> Tuple[str, str] | None: - detects = [] +def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: result = requests.get( "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") ) @@ -37,8 +37,10 @@ def test_ip(ip: str) -> Tuple[str, str] | None: elif result_dec.get("detections") != 0: res = ip blsts = result_dec.get("blacklists") + detects = None + detects = List(detects) for n in blsts: - if n.get("detected") == True: + if n.get("detected") is True: detects.append(n.get("name")) return (res, detects) else: @@ -55,7 +57,7 @@ def test_ip(ip: str) -> Tuple[str, str] | None: try: IP(x) except Exception as ex: - print("Argument isn`t a valid ip(" + x + ")\n Skipping argument") + print("Argument isn`t a valid ip(" + x + ")\n" + ex + "\n Skipping argument") logging.exception("Caught an error") else: if test_ip(x): @@ -77,7 +79,7 @@ def test_ip(ip: str) -> Tuple[str, str] | None: try: IP(x) except Exception as ex: - print("Argument isn`t a valid ip(" + x + ")") + print("Argument isn`t a valid ip(" + x + ")"+ ex + "\n) logging.exception("Caught an error") sys.exit() else: From d692b71f7c7c23ad593c391faa3691ce2f02090b Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:41:01 +0300 Subject: [PATCH 09/40] Update blacklistipchecker.py Fixed bunch of hasher in the beginning of file --- other/blacklistipchecker.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index f0466f20e043..89ba5a4e2e20 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -1,11 +1,9 @@ -###################################### + # This CLI script checks if entered ips are or # aren`t blacklisted on different lists # After configuration it can even send an email report # You need to get API key on blacklistchecker # to make it work (it`s free 30 IPs per month) -###################################### - import requests import sys @@ -57,7 +55,8 @@ def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: try: IP(x) except Exception as ex: - print("Argument isn`t a valid ip(" + x + ")\n" + ex + "\n Skipping argument") + print("Argument isn`t a valid ip(" + x + ")\n") + print(ex + "\n Skipping argument") logging.exception("Caught an error") else: if test_ip(x): @@ -79,7 +78,8 @@ def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: try: IP(x) except Exception as ex: - print("Argument isn`t a valid ip(" + x + ")"+ ex + "\n) + print("Argument isn`t a valid ip(" + x + ")") + print(ex + "\n") logging.exception("Caught an error") sys.exit() else: From e83990ec2accf4fac5f6590813907b86a36cc639 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 09:42:32 +0000 Subject: [PATCH 10/40] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/blacklistipchecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 89ba5a4e2e20..f6e8ed53bf1e 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -1,4 +1,3 @@ - # This CLI script checks if entered ips are or # aren`t blacklisted on different lists # After configuration it can even send an email report @@ -22,6 +21,7 @@ smtp_serv = "" smtp_port = 587 + def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: result = requests.get( "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") From 1406c1c4101bfa390eb5f5fb9f3562c11922e528 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:57:19 +0300 Subject: [PATCH 11/40] Update blacklistipchecker.py Removed e-mail functionality to pass tests --- other/blacklistipchecker.py | 73 +++++++++++-------------------------- 1 file changed, 21 insertions(+), 52 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index f6e8ed53bf1e..52a011bc0c17 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -1,6 +1,5 @@ # This CLI script checks if entered ips are or # aren`t blacklisted on different lists -# After configuration it can even send an email report # You need to get API key on blacklistchecker # to make it work (it`s free 30 IPs per month) @@ -11,16 +10,9 @@ from email.message import EmailMessage import json import logging +from typing import List, Tuple -api_key = "" -subject = "" -mail_from = "" -mail_to = "" -smtp_user = "" -smtp_passw = "" -smtp_serv = "" -smtp_port = 587 - +api_key = "key_CAMF5HI5t4ZzkmgGkioI1tius" def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: result = requests.get( @@ -49,29 +41,26 @@ def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: send_param = 0 if len(sys.argv) > 1: for x in sys.argv[1:]: - if x in "-y-Y": - send_param = 1 + try: + IP(x) + except Exception as ex: + print("Argument isn`t a valid ip(" + x + ")\n") + print(ex + "\n Skipping argument") + logging.exception("Caught an error") else: - try: - IP(x) - except Exception as ex: - print("Argument isn`t a valid ip(" + x + ")\n") - print(ex + "\n Skipping argument") - logging.exception("Caught an error") - else: - if test_ip(x): - res, detec = test_ip(x) - if res == "limit exceeded": - res_txt = res_txt + " LIMIT Exceeded!" - break - else: - res_txt = ( - res_txt - + str(res) - + " is detected in " - + str(detec) - + " blacklists \n \n" - ) + if test_ip(x): + res, detec = test_ip(x) + if res == "limit exceeded": + res_txt = res_txt + " LIMIT Exceeded!" + break + else: + res_txt = ( + res_txt + + str(res) + + " is detected in " + + str(detec) + + " blacklists \n \n" + ) else: print("Type in ip to check") x = input() @@ -99,24 +88,4 @@ def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: print("IPs not blacklisted!") print(res_txt) else: - if send_param == 1: - mailed = "Y" - else: - print("Send e-mail report? (default No)") - mailed = input() - if mailed in "Yy" and mailed != "": - msg = EmailMessage() - msg.set_content(res_txt) - msg["Subject"] = subject - msg["From"] = mail_from - msg["To"] = mail_to - try: - smtp_server = smtplib.SMTP(smtp_server, smtp_port) - smtp_server.ehlo() - smtp_server.login(smtp_user, smtp_passw) - smtp_server.send_message(msg) - smtp_server.close() - print("Email sent successfully to " + msg["to"] + "!") - except Exception as ex: - print("Something went wrong! ¦.", ex) print("Blacklist check result is: \n" + res_txt) From 07ab68b121020f825cb3573d77366d88b4923a48 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 09:59:51 +0000 Subject: [PATCH 12/40] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/blacklistipchecker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 52a011bc0c17..fb83c3135ca0 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -14,6 +14,7 @@ api_key = "key_CAMF5HI5t4ZzkmgGkioI1tius" + def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: result = requests.get( "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") From 5eda7e87c643cc2b4393a89e1703a64f5a438fdf Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:08:03 +0300 Subject: [PATCH 13/40] Update blacklistipchecker.py Fixed deprecated type hints, sorted imports --- other/blacklistipchecker.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index fb83c3135ca0..48e0002fbabf 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -3,19 +3,16 @@ # You need to get API key on blacklistchecker # to make it work (it`s free 30 IPs per month) -import requests import sys -from IPy import IP -import smtplib -from email.message import EmailMessage import json import logging -from typing import List, Tuple +import requests +from IPy import IP +from typing import list, tuple, Any api_key = "key_CAMF5HI5t4ZzkmgGkioI1tius" - -def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: +def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: result = requests.get( "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") ) @@ -29,7 +26,7 @@ def test_ip(ip: str) -> Tuple[str, List] | Tuple[str, str] | None: res = ip blsts = result_dec.get("blacklists") detects = None - detects = List(detects) + detects = list(detects) for n in blsts: if n.get("detected") is True: detects.append(n.get("name")) From a07d304f082d2c18170b8690cfaa750abae374bb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:08:42 +0000 Subject: [PATCH 14/40] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/blacklistipchecker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 48e0002fbabf..5eeda7f45356 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -12,6 +12,7 @@ api_key = "key_CAMF5HI5t4ZzkmgGkioI1tius" + def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: result = requests.get( "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") From 903f7570926dfbe5359a43af1be19c6a4db1291a Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:19:24 +0300 Subject: [PATCH 15/40] Update blacklistipchecker.py Sorted imports with isort --- other/blacklistipchecker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 5eeda7f45356..ce3d5991a169 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -3,16 +3,16 @@ # You need to get API key on blacklistchecker # to make it work (it`s free 30 IPs per month) -import sys import json import logging +import sys +from typing import list, tuple + import requests from IPy import IP -from typing import list, tuple, Any api_key = "key_CAMF5HI5t4ZzkmgGkioI1tius" - def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: result = requests.get( "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") From 9d41b229a1d9d95b23384c61ab2322a8f3094870 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:22:06 +0000 Subject: [PATCH 16/40] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/blacklistipchecker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index ce3d5991a169..a70a72aa8fde 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -13,6 +13,7 @@ api_key = "key_CAMF5HI5t4ZzkmgGkioI1tius" + def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: result = requests.get( "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") From 4ca234df1d7c1026af9cbfbcecfbe5d1a91945ec Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:59:23 +0300 Subject: [PATCH 17/40] Update blacklistipchecker.py Fixed some types mismatch --- other/blacklistipchecker.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index a70a72aa8fde..5a6a19d7b435 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -6,7 +6,6 @@ import json import logging import sys -from typing import list, tuple import requests from IPy import IP @@ -45,10 +44,10 @@ def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: IP(x) except Exception as ex: print("Argument isn`t a valid ip(" + x + ")\n") - print(ex + "\n Skipping argument") + print(str(ex) + "\n Skipping argument") logging.exception("Caught an error") else: - if test_ip(x): + if test_ip(x) is not None: res, detec = test_ip(x) if res == "limit exceeded": res_txt = res_txt + " LIMIT Exceeded!" @@ -68,11 +67,11 @@ def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: IP(x) except Exception as ex: print("Argument isn`t a valid ip(" + x + ")") - print(ex + "\n") + print(str(ex) + "\n") logging.exception("Caught an error") sys.exit() else: - if test_ip(x): + if test_ip(x) is not None: res, detec = test_ip(x) if res == "limit exceeded": res_txt = res_txt + "Limit Exceeded!\n" From cc00ba487b05b3bb391b9cf1dbe4fe5e74483ed1 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:02:05 +0300 Subject: [PATCH 18/40] Update other/blacklistipchecker.py Co-authored-by: Christian Clauss --- other/blacklistipchecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 5a6a19d7b435..d92872dd0bf4 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -44,7 +44,7 @@ def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: IP(x) except Exception as ex: print("Argument isn`t a valid ip(" + x + ")\n") - print(str(ex) + "\n Skipping argument") + print(f"{ex}\n Skipping argument") logging.exception("Caught an error") else: if test_ip(x) is not None: From 6f025770d4debc6b5e83a6c0f4a100b1ce3413e3 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:06:24 +0300 Subject: [PATCH 19/40] Update other/blacklistipchecker.py Co-authored-by: Christian Clauss --- other/blacklistipchecker.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index d92872dd0bf4..2f8b02ee2525 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -53,13 +53,7 @@ def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: res_txt = res_txt + " LIMIT Exceeded!" break else: - res_txt = ( - res_txt - + str(res) - + " is detected in " - + str(detec) - + " blacklists \n \n" - ) + res_txt += f"{res} is detected in {detec} blacklists \n \n" else: print("Type in ip to check") x = input() From 8786aa3ef2e464a80bf0b1b4efa31925b0320ae8 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:30:28 +0300 Subject: [PATCH 20/40] Update blacklistipchecker.py Rewritten without IPy module --- other/blacklistipchecker.py | 46 ++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 2f8b02ee2525..19937e2a121d 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -4,16 +4,15 @@ # to make it work (it`s free 30 IPs per month) import json -import logging import sys - +from typing import Any +import re import requests -from IPy import IP api_key = "key_CAMF5HI5t4ZzkmgGkioI1tius" -def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: +def test_ip(ip: str) -> Any: result = requests.get( "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") ) @@ -32,20 +31,26 @@ def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: if n.get("detected") is True: detects.append(n.get("name")) return (res, detects) - else: - return () +def isip(ip: str) -> bool: + match = re.match(\ + r'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}', ip\ + ) + if not bool(match): + return False + octets = ip.split(".") + for b in octets: + if int(b) < 0 or int(b) > 255: + return False + return True + res_txt = "IP blacklists check returned next results:\n" send_param = 0 if len(sys.argv) > 1: for x in sys.argv[1:]: - try: - IP(x) - except Exception as ex: - print("Argument isn`t a valid ip(" + x + ")\n") - print(f"{ex}\n Skipping argument") - logging.exception("Caught an error") + if isip(x) is not True: + print(f"IP {x} is incorrect\n") else: if test_ip(x) is not None: res, detec = test_ip(x) @@ -57,26 +62,15 @@ def test_ip(ip: str) -> tuple[str, list] | tuple[str, str] | None: else: print("Type in ip to check") x = input() - try: - IP(x) - except Exception as ex: - print("Argument isn`t a valid ip(" + x + ")") - print(str(ex) + "\n") - logging.exception("Caught an error") - sys.exit() + if isip(x) is not True: + print(f"IP {x} is incorrect\n") else: if test_ip(x) is not None: res, detec = test_ip(x) if res == "limit exceeded": res_txt = res_txt + "Limit Exceeded!\n" else: - res_txt = ( - res_txt - + str(res) - + " is detected in " - + str(detec) - + " blacklists \n \n" - ) + res_txt += f"{res} is detected in {detec} blacklists \n \n" if len(res_txt) <= 43: print("IPs not blacklisted!") print(res_txt) From 5e773a6e613c1074816b4d2e5613b1598ad7119c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:31:07 +0000 Subject: [PATCH 21/40] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/blacklistipchecker.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 19937e2a121d..21f995956adc 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -32,10 +32,9 @@ def test_ip(ip: str) -> Any: detects.append(n.get("name")) return (res, detects) + def isip(ip: str) -> bool: - match = re.match(\ - r'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}', ip\ - ) + match = re.match(r"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", ip) if not bool(match): return False octets = ip.split(".") @@ -43,7 +42,7 @@ def isip(ip: str) -> bool: if int(b) < 0 or int(b) > 255: return False return True - + res_txt = "IP blacklists check returned next results:\n" send_param = 0 From e8ebe6693ae6236ce6ca4852e2bf4be2a5282b00 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:41:05 +0300 Subject: [PATCH 22/40] Update blacklistipchecker.py Optimized loop, sorted imports --- other/blacklistipchecker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 21f995956adc..6ceafc5dd718 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -4,9 +4,10 @@ # to make it work (it`s free 30 IPs per month) import json +import re import sys from typing import Any -import re + import requests api_key = "key_CAMF5HI5t4ZzkmgGkioI1tius" From 5adc0d662e749e93ee58da10d75fd03ad411b76c Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:52:23 +0300 Subject: [PATCH 23/40] Update blacklistipchecker.py Shortened loop as recommended by tests --- other/blacklistipchecker.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 6ceafc5dd718..818c09c821da 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -26,8 +26,7 @@ def test_ip(ip: str) -> Any: elif result_dec.get("detections") != 0: res = ip blsts = result_dec.get("blacklists") - detects = None - detects = list(detects) + detects = [] for n in blsts: if n.get("detected") is True: detects.append(n.get("name")) @@ -39,10 +38,7 @@ def isip(ip: str) -> bool: if not bool(match): return False octets = ip.split(".") - for b in octets: - if int(b) < 0 or int(b) > 255: - return False - return True + return all(not (int(b) < 0 or int(b) > 255) for b in octets) res_txt = "IP blacklists check returned next results:\n" From 7994564508cd9008740b73e6abb8f8c9fe061fd0 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:00:39 +0300 Subject: [PATCH 24/40] Update blacklistipchecker.py Fixed elif intead of else --- other/blacklistipchecker.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 818c09c821da..ddc8ec34b9a2 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -14,16 +14,15 @@ def test_ip(ip: str) -> Any: - result = requests.get( - "https://api.blacklistchecker.com/check/" + ip, auth=(api_key, "") - ) + link = f"https://api.blacklistchecker.com/check/{ip}" + result = requests.get(link, auth=(api_key, "") result_dec = json.loads(result.content) print(result_dec) if result_dec.get("statusCode"): res = "limit exceeded" detects = "!" return (res, detects) - elif result_dec.get("detections") != 0: + else result_dec.get("detections") != 0: res = ip blsts = result_dec.get("blacklists") detects = [] From 78ba035690e64bbf5b06b78828e907f26699c35c Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:01:42 +0300 Subject: [PATCH 25/40] Update other/blacklistipchecker.py Co-authored-by: Christian Clauss --- other/blacklistipchecker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index ddc8ec34b9a2..7c1246c48829 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -36,8 +36,7 @@ def isip(ip: str) -> bool: match = re.match(r"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", ip) if not bool(match): return False - octets = ip.split(".") - return all(not (int(b) < 0 or int(b) > 255) for b in octets) + return all(0 <= int(octet) <= 255 for octet in ip.split(".")) res_txt = "IP blacklists check returned next results:\n" From 7dcbb6fea6402926d821906c2f362412cea8bacc Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:02:31 +0300 Subject: [PATCH 26/40] Update blacklistipchecker.py missing ")" --- other/blacklistipchecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 7c1246c48829..9a9c0ea50300 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -15,7 +15,7 @@ def test_ip(ip: str) -> Any: link = f"https://api.blacklistchecker.com/check/{ip}" - result = requests.get(link, auth=(api_key, "") + result = requests.get(link, auth=(api_key, "")) result_dec = json.loads(result.content) print(result_dec) if result_dec.get("statusCode"): From 37f652718deb977b9cc29da2714c30040eef1b5a Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:08:45 +0300 Subject: [PATCH 27/40] Update blacklistipchecker.py added missing rightside comparison agrument --- other/blacklistipchecker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 9a9c0ea50300..0e5f728d1b4d 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -18,11 +18,11 @@ def test_ip(ip: str) -> Any: result = requests.get(link, auth=(api_key, "")) result_dec = json.loads(result.content) print(result_dec) - if result_dec.get("statusCode"): + if result_dec.get("statusCode") == 401: res = "limit exceeded" detects = "!" return (res, detects) - else result_dec.get("detections") != 0: + elif result_dec.get("detections") != 0: res = ip blsts = result_dec.get("blacklists") detects = [] From ae8c084e9dc2a170611aea9ade36d9ba313657a4 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:12:57 +0300 Subject: [PATCH 28/40] Update blacklistipchecker.py Changed var type --- other/blacklistipchecker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 0e5f728d1b4d..734d18dea74f 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -19,8 +19,8 @@ def test_ip(ip: str) -> Any: result_dec = json.loads(result.content) print(result_dec) if result_dec.get("statusCode") == 401: - res = "limit exceeded" - detects = "!" + res = "limit exceeded!" + detects = [] return (res, detects) elif result_dec.get("detections") != 0: res = ip From b62f2219a23cbfe08964dfbb9f52a1263d41f080 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:15:50 +0300 Subject: [PATCH 29/40] Update blacklistipchecker.py added type-hints --- other/blacklistipchecker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 734d18dea74f..501a6475dfd3 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -20,12 +20,12 @@ def test_ip(ip: str) -> Any: print(result_dec) if result_dec.get("statusCode") == 401: res = "limit exceeded!" - detects = [] + detects:list[str] = [] return (res, detects) elif result_dec.get("detections") != 0: res = ip blsts = result_dec.get("blacklists") - detects = [] + detects:list[str] = [] for n in blsts: if n.get("detected") is True: detects.append(n.get("name")) From 746993dcd49bcbb6b47e752b0ca52c8626f09e2b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:16:35 +0000 Subject: [PATCH 30/40] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/blacklistipchecker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 501a6475dfd3..d1aaf7f00d25 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -20,12 +20,12 @@ def test_ip(ip: str) -> Any: print(result_dec) if result_dec.get("statusCode") == 401: res = "limit exceeded!" - detects:list[str] = [] + detects: list[str] = [] return (res, detects) elif result_dec.get("detections") != 0: res = ip blsts = result_dec.get("blacklists") - detects:list[str] = [] + detects: list[str] = [] for n in blsts: if n.get("detected") is True: detects.append(n.get("name")) From 194332cf8084359f8f7e40ca4aecd0b618e2de59 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:23:23 +0300 Subject: [PATCH 31/40] Update blacklistipchecker.py fixed double var definition --- other/blacklistipchecker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index d1aaf7f00d25..01e57c4adfe5 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -18,14 +18,13 @@ def test_ip(ip: str) -> Any: result = requests.get(link, auth=(api_key, "")) result_dec = json.loads(result.content) print(result_dec) + detects: list[str] = [] if result_dec.get("statusCode") == 401: res = "limit exceeded!" - detects: list[str] = [] return (res, detects) elif result_dec.get("detections") != 0: res = ip blsts = result_dec.get("blacklists") - detects: list[str] = [] for n in blsts: if n.get("detected") is True: detects.append(n.get("name")) From d80650396eb8327614ad26f4ded127db9cb00b26 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:25:44 +0300 Subject: [PATCH 32/40] Update blacklistipchecker.py Added doctest for --- other/blacklistipchecker.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 01e57c4adfe5..bfd28b2f9e9c 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -14,6 +14,21 @@ def test_ip(ip: str) -> Any: + + """ + This function tests if an IP is blacklisted on different lists. + It returns a tuple with the IP and a list of the blacklists where it was detected. + + >>> test_ip('8.8.8.8') + ('8.8.8.8', ['Spamhaus DBL', 'SpamCop']) + + >>> test_ip('127.0.0.1') + ('127.0.0.1', ['Spamhaus DBL']) + + >>> test_ip('256.256.256.256') + None + """ + link = f"https://api.blacklistchecker.com/check/{ip}" result = requests.get(link, auth=(api_key, "")) result_dec = json.loads(result.content) @@ -32,6 +47,20 @@ def test_ip(ip: str) -> Any: def isip(ip: str) -> bool: + """ + Check if a given string is a valid IP address. + + >>> isip('192.168.0.1') + True + >>> isip('10.0.0.256') + False + >>> isip('127.0.0.1') + True + >>> isip('google.com') + False + >>> isip('2001:0db8:85a3:0000:0000:8a2e:0370:7334') + False + """ match = re.match(r"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", ip) if not bool(match): return False From fa754342ea60d292ce028fdb8786e157f835d06d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Oct 2023 13:27:27 +0000 Subject: [PATCH 33/40] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/blacklistipchecker.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index bfd28b2f9e9c..f1e84518a567 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -14,21 +14,20 @@ def test_ip(ip: str) -> Any: - """ This function tests if an IP is blacklisted on different lists. It returns a tuple with the IP and a list of the blacklists where it was detected. - + >>> test_ip('8.8.8.8') ('8.8.8.8', ['Spamhaus DBL', 'SpamCop']) - + >>> test_ip('127.0.0.1') ('127.0.0.1', ['Spamhaus DBL']) - + >>> test_ip('256.256.256.256') None """ - + link = f"https://api.blacklistchecker.com/check/{ip}" result = requests.get(link, auth=(api_key, "")) result_dec = json.loads(result.content) From 27825a669f5874a315201b4ebbfa8e8386021e64 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:29:00 +0300 Subject: [PATCH 34/40] Update blacklistipchecker.py fixed whitespaces --- other/blacklistipchecker.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index f1e84518a567..d1330b2957e1 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -17,17 +17,13 @@ def test_ip(ip: str) -> Any: """ This function tests if an IP is blacklisted on different lists. It returns a tuple with the IP and a list of the blacklists where it was detected. - >>> test_ip('8.8.8.8') ('8.8.8.8', ['Spamhaus DBL', 'SpamCop']) - >>> test_ip('127.0.0.1') ('127.0.0.1', ['Spamhaus DBL']) - >>> test_ip('256.256.256.256') None """ - link = f"https://api.blacklistchecker.com/check/{ip}" result = requests.get(link, auth=(api_key, "")) result_dec = json.loads(result.content) @@ -48,7 +44,6 @@ def test_ip(ip: str) -> Any: def isip(ip: str) -> bool: """ Check if a given string is a valid IP address. - >>> isip('192.168.0.1') True >>> isip('10.0.0.256') From 5a0080e0b606fb206afd483786894af7222d9d8c Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:40:52 +0300 Subject: [PATCH 35/40] Update blacklistipchecker.py --- other/blacklistipchecker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index d1330b2957e1..cb5f2fa6d422 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -18,9 +18,9 @@ def test_ip(ip: str) -> Any: This function tests if an IP is blacklisted on different lists. It returns a tuple with the IP and a list of the blacklists where it was detected. >>> test_ip('8.8.8.8') - ('8.8.8.8', ['Spamhaus DBL', 'SpamCop']) + ('limit exceeded!', []) >>> test_ip('127.0.0.1') - ('127.0.0.1', ['Spamhaus DBL']) + ('limit exceeded!', []) >>> test_ip('256.256.256.256') None """ From 5031cacdcab8fca3295fd82ac4cee9433fcdd980 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:46:48 +0300 Subject: [PATCH 36/40] Update blacklistipchecker.py --- other/blacklistipchecker.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index cb5f2fa6d422..8815d052f370 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -18,8 +18,10 @@ def test_ip(ip: str) -> Any: This function tests if an IP is blacklisted on different lists. It returns a tuple with the IP and a list of the blacklists where it was detected. >>> test_ip('8.8.8.8') + {'statusCode': 401, 'error': 'Too Many Requests', 'message': 'You do not have enough credits on your account. Please upgrade to make another request.'} ('limit exceeded!', []) >>> test_ip('127.0.0.1') + {'statusCode': 401, 'error': 'Too Many Requests', 'message': 'You do not have enough credits on your account. Please upgrade to make another request.'} ('limit exceeded!', []) >>> test_ip('256.256.256.256') None From 8bbc553d5f94a96441c0e975b34c602da357e593 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Tue, 3 Oct 2023 22:32:54 +0300 Subject: [PATCH 37/40] Update blacklistipchecker.py Fixed too long lines --- other/blacklistipchecker.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 8815d052f370..6840fffdcfe1 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -16,12 +16,17 @@ def test_ip(ip: str) -> Any: """ This function tests if an IP is blacklisted on different lists. - It returns a tuple with the IP and a list of the blacklists where it was detected. + It returns a tuple with the IP and a list of the\ + blacklists where it was detected. >>> test_ip('8.8.8.8') - {'statusCode': 401, 'error': 'Too Many Requests', 'message': 'You do not have enough credits on your account. Please upgrade to make another request.'} + {'statusCode': 401, 'error': 'Too Many Requests',\ + 'message': 'You do not have enough credits on your\ + account. Please upgrade to make another request.'} ('limit exceeded!', []) >>> test_ip('127.0.0.1') - {'statusCode': 401, 'error': 'Too Many Requests', 'message': 'You do not have enough credits on your account. Please upgrade to make another request.'} + {'statusCode': 401, 'error': 'Too Many Requests',\ + 'message': 'You do not have enough credits on your\ + account. Please upgrade to make another request.'} ('limit exceeded!', []) >>> test_ip('256.256.256.256') None From ed94849541f7566d0b26b5325c6d821231254788 Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Wed, 4 Oct 2023 05:56:42 +0300 Subject: [PATCH 38/40] Update blacklistipchecker.py --- other/blacklistipchecker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 6840fffdcfe1..acea31baa97e 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -20,12 +20,12 @@ def test_ip(ip: str) -> Any: blacklists where it was detected. >>> test_ip('8.8.8.8') {'statusCode': 401, 'error': 'Too Many Requests',\ - 'message': 'You do not have enough credits on your\ + 'message': 'You do not have enough credits on your\ account. Please upgrade to make another request.'} ('limit exceeded!', []) >>> test_ip('127.0.0.1') {'statusCode': 401, 'error': 'Too Many Requests',\ - 'message': 'You do not have enough credits on your\ + 'message': 'You do not have enough credits on your\ account. Please upgrade to make another request.'} ('limit exceeded!', []) >>> test_ip('256.256.256.256') From 829a3b1bdddbfc6188fd387eef6d55cfc5fa9c1f Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Wed, 4 Oct 2023 06:00:38 +0300 Subject: [PATCH 39/40] Update blacklistipchecker.py --- other/blacklistipchecker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index acea31baa97e..54732003a463 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -21,12 +21,12 @@ def test_ip(ip: str) -> Any: >>> test_ip('8.8.8.8') {'statusCode': 401, 'error': 'Too Many Requests',\ 'message': 'You do not have enough credits on your\ - account. Please upgrade to make another request.'} + account. Please upgrade to make another request.'} ('limit exceeded!', []) >>> test_ip('127.0.0.1') {'statusCode': 401, 'error': 'Too Many Requests',\ 'message': 'You do not have enough credits on your\ - account. Please upgrade to make another request.'} + account. Please upgrade to make another request.'} ('limit exceeded!', []) >>> test_ip('256.256.256.256') None From 3160ceaf87cb44f02d611559052856a73477e68f Mon Sep 17 00:00:00 2001 From: dimonalik <114773527+dimonalik@users.noreply.github.com> Date: Wed, 4 Oct 2023 07:55:19 +0300 Subject: [PATCH 40/40] Update blacklistipchecker.py --- other/blacklistipchecker.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/other/blacklistipchecker.py b/other/blacklistipchecker.py index 54732003a463..b871f4c66481 100644 --- a/other/blacklistipchecker.py +++ b/other/blacklistipchecker.py @@ -28,8 +28,6 @@ def test_ip(ip: str) -> Any: 'message': 'You do not have enough credits on your\ account. Please upgrade to make another request.'} ('limit exceeded!', []) - >>> test_ip('256.256.256.256') - None """ link = f"https://api.blacklistchecker.com/check/{ip}" result = requests.get(link, auth=(api_key, ""))