Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
69e5683
Create blacklistipchecker.py
dimonalik Oct 2, 2023
c66872c
updating DIRECTORY.md
Oct 2, 2023
7cf1665
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2023
fbf9f42
Update blacklistipchecker.py
dimonalik Oct 2, 2023
83e7036
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2023
283e633
Update blacklistipchecker.py
dimonalik Oct 2, 2023
616c1db
Update blacklistipchecker.py
dimonalik Oct 2, 2023
d10e271
Update blacklistipchecker.py
dimonalik Oct 2, 2023
d692b71
Update blacklistipchecker.py
dimonalik Oct 2, 2023
e83990e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2023
1406c1c
Update blacklistipchecker.py
dimonalik Oct 2, 2023
07ab68b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2023
5eda7e8
Update blacklistipchecker.py
dimonalik Oct 2, 2023
a07d304
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2023
903f757
Update blacklistipchecker.py
dimonalik Oct 2, 2023
9d41b22
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2023
4ca234d
Update blacklistipchecker.py
dimonalik Oct 2, 2023
cc00ba4
Update other/blacklistipchecker.py
dimonalik Oct 2, 2023
6f02577
Update other/blacklistipchecker.py
dimonalik Oct 2, 2023
8786aa3
Update blacklistipchecker.py
dimonalik Oct 2, 2023
5e773a6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2023
e8ebe66
Update blacklistipchecker.py
dimonalik Oct 2, 2023
5adc0d6
Update blacklistipchecker.py
dimonalik Oct 2, 2023
7994564
Update blacklistipchecker.py
dimonalik Oct 2, 2023
78ba035
Update other/blacklistipchecker.py
dimonalik Oct 2, 2023
7dcbb6f
Update blacklistipchecker.py
dimonalik Oct 2, 2023
37f6527
Update blacklistipchecker.py
dimonalik Oct 2, 2023
ae8c084
Update blacklistipchecker.py
dimonalik Oct 2, 2023
b62f221
Update blacklistipchecker.py
dimonalik Oct 2, 2023
746993d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2023
194332c
Update blacklistipchecker.py
dimonalik Oct 2, 2023
d806503
Update blacklistipchecker.py
dimonalik Oct 3, 2023
fa75434
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 3, 2023
27825a6
Update blacklistipchecker.py
dimonalik Oct 3, 2023
5a0080e
Update blacklistipchecker.py
dimonalik Oct 3, 2023
5031cac
Update blacklistipchecker.py
dimonalik Oct 3, 2023
8bbc553
Update blacklistipchecker.py
dimonalik Oct 3, 2023
ed94849
Update blacklistipchecker.py
dimonalik Oct 4, 2023
829a3b1
Update blacklistipchecker.py
dimonalik Oct 4, 2023
3160cea
Update blacklistipchecker.py
dimonalik Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DIRECTORY.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand DownExpand Up@@ -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)
Expand Down
99 changes: 99 additions & 0 deletions other/blacklistipchecker.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
# This CLI script checks if entered ips are or
# aren`t blacklisted on different lists
# You need to get API key on blacklistchecker
# to make it work (it`s free 30 IPs per month)

import json
import re
import sys
from typing import Any

import requests

api_key = "key_CAMF5HI5t4ZzkmgGkioI1tius"


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!', [])
"""
link = f"https://api.blacklistchecker.com/check/{ip}"
result = requests.get(link, auth=(api_key, ""))
result_dec = json.loads(result.content)
print(result_dec)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error occurred while parsing the file: other/blacklistipchecker.py

Traceback (mostrecentcalllast):
File"/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line146, inparsereports=lint_file(
^^^^^^^^^^libcst._exceptions.ParserSyntaxError: SyntaxError @ 20:16.parsererror: errorat19:15: expectedoneof!=, %, &, (, *, **, +, ,, -, ., /, //, <, <<, <=, ==, >, >=, >>, @, [, ^, and, if, in, is, not, or, |print(result_dec)
^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error occurred while parsing the file: other/blacklistipchecker.py

Traceback (mostrecentcalllast):
File"/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line146, inparsereports=lint_file(
^^^^^^^^^^libcst._exceptions.ParserSyntaxError: SyntaxError @ 20:16.parsererror: errorat19:15: expectedoneof!=, %, &, (, *, **, +, ,, -, ., /, //, <, <<, <=, ==, >, >=, >>, @, [, ^, and, if, in, is, not, or, |print(result_dec)
^

detects: list[str] = []
if result_dec.get("statusCode") == 401:
res = "limit exceeded!"
return (res, detects)
elif result_dec.get("detections") != 0:
res = ip

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error occurred while parsing the file: other/blacklistipchecker.py

Traceback (mostrecentcalllast):
File"/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line146, inparsereports=lint_file(
^^^^^^^^^^libcst._exceptions.ParserSyntaxError: SyntaxError @ 26:17.parsererror: errorat25:19: expected :
res=ip^

blsts = result_dec.get("blacklists")
for n in blsts:
if n.get("detected") is True:
detects.append(n.get("name"))
return (res, detects)


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
return all(0 <= int(octet) <= 255 for octet in ip.split("."))


res_txt = "IP blacklists check returned next results:\n"
send_param = 0
if len(sys.argv) > 1:
for x in sys.argv[1:]:
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!"
break
else:
res_txt += f"{res} is detected in {detec} blacklists \n \n"
else:
print("Type in ip to check")
x = input()
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 += f"{res} is detected in {detec} blacklists \n \n"
if len(res_txt) <= 43:
print("IPs not blacklisted!")
print(res_txt)
else:
print("Blacklist check result is: \n" + res_txt)