-
- Notifications
You must be signed in to change notification settings - Fork 49.2k
Create blacklistipchecker.py #9416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
69e5683 c66872c 7cf1665 fbf9f42 83e7036 283e633 616c1db d10e271 d692b71 e83990e 1406c1c 07ab68b 5eda7e8 a07d304 903f757 9d41b22 4ca234d cc00ba4 6f02577 8786aa3 5e773a6 e8ebe66 5adc0d6 7994564 78ba035 7dcbb6f 37f6527 ae8c084 b62f221 746993d 194332c d806503 fa75434 27825a6 5a0080e 5031cac 8bbc553 ed94849 829a3b1 3160cea File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| ###################################### | ||
| # 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 | ||
| import logging | ||
| | ||
| API_key = '' | ||
cclauss marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| subject = '' | ||
| mail_from = '' | ||
| mail_to = '' | ||
| smtp_user = '' | ||
| smtp_passw = '' | ||
| smtp_serv = '' | ||
| smtp_port = 587 | ||
| | ||
| def test_ip(ip): | ||
cclauss marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| detects = [] | ||
cclauss marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| result = requests.get('https://api.blacklistchecker.com/check/'+ip, auth=(API_Key,'')) | ||
| result_dec = json.loads(result.content) | ||
| print(result_dec) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An error occurred while parsing the file: Traceback (most recent call last): File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse reports = lint_file( ^^^^^^^^^^ libcst._exceptions.ParserSyntaxError: Syntax Error @ 20:16. parser error: error at 19:15: expected one of !=, %, &, (, *, **, +, ,, -, ., /, //, <, <<, <=, ==, >, >=, >>, @, [, ^, and, if, in, is, not, or, | print(result_dec) ^There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An error occurred while parsing the file: Traceback (most recent call last): File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse reports = lint_file( ^^^^^^^^^^ libcst._exceptions.ParserSyntaxError: Syntax Error @ 20:16. parser error: error at 19:15: expected one of !=, %, &, (, *, **, +, ,, -, ., /, //, <, <<, <=, ==, >, >=, >>, @, [, ^, and, if, in, is, not, or, | print(result_dec) ^ | ||
| if result_dec.get('statusCode'): | ||
| res="limit exceeded" | ||
| detects = "!" | ||
| return(res, detects) | ||
| elif result_dec.get('detections') != 0: | ||
| res = ip | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An error occurred while parsing the file: Traceback (most recent call last): File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse reports = lint_file( ^^^^^^^^^^ libcst._exceptions.ParserSyntaxError: Syntax Error @ 26:17. parser error: error at 25:19: expected : 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 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) | ||
| 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 Exception as ex: | ||
| 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' | ||
| 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'] = 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) | ||
There was a problem hiding this comment.
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.pyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhruvmanila ?