Skip to content

Commit

Permalink
fixed ip module terminal output
Browse files Browse the repository at this point in the history
black-ified ✨ 🍰 ✨
  • Loading branch information
kash committed Apr 11, 2023
1 parent e908948 commit bc07314
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
70 changes: 45 additions & 25 deletions IP/ip_reputation_checker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import sys
import json
import logging
import logging.config
from Common import utils as utils
from Common.utils import KeyFetcher
from Common.utils import Validator
import requests
import json
from Common.breach_checker import BreachChecker
from Config.config import configure_logging
from termcolor import colored
import requests
from Common import utils

configure_logging()

Expand All @@ -16,40 +21,55 @@ def __init__(self, ip_address):

# Check Virus Total IP reputation
def checkIPReputationVT(self, ip_address):
"""This is a method that checks IP reputation from Virus Total
Args:
ip_address (IP): _description_
Returns:
_null_: No return value
"""
keyfetch_vt = KeyFetcher()
vtkey: str = keyfetch_vt.getVTAPIKey() # pyright: ignore
validator = Validator()
validator.check_VTAPIkey(vtkey)

logging.info("Checking IP reputation from Virus Total for ip:", ip_address)
# Check IP reputation from Virus Total
logging.info(
"\n\n{}{}".format(
colored("Checking IP reputation from Virus Total for ip: ", "blue"),
colored(ip_address, "red"),
)
)
url = "https://www.virustotal.com/api/v3/ip_addresses/" + ip_address
payload = {}
headers: dict[str, str] = {"x-apikey": vtkey}
response = requests.request("GET", url, headers=headers, data=payload).text
data = json.loads(response)
# pretty print full json response
# print(json.dumps(data, indent=4, sort_keys=True))
results = data["data"]["attributes"]["total_votes"]
return results
print(
json.dumps(
data["data"]["attributes"]["total_votes"], indent=4, sort_keys=True
)
)
# results = data["data"]["attributes"]["total_votes"]
# return results

# Check Talos IP reputation
def checkIPReputationTalos(self, ip_list):
# Check IP reputation from Cisco Talos
# https://talosintelligence.com/reputation_center/lookup?search=
# User requests to check IP reputation from Cisco Talos
logging.info("Checking IP reputation from Cisco Talos")
for ip in ip_list:
url = "https://talosintelligence.com/reputation_center/lookup?search=" + ip
response = requests.request("GET", url).text
if (
"This IP address has been observed to be associated with malicious activity."
in response
):
logging.info("IP: " + ip + " is malicious")
# self.bad_ip_list.append(ip)
else:
logging.info("IP: " + ip + " is not malicious")
# # Check Talos IP reputation
# def checkIPReputationTalos(self, ip_list):
# # Check IP reputation from Cisco Talos
# # https://talosintelligence.com/reputation_center/lookup?search=
# # User requests to check IP reputation from Cisco Talos
# logging.info("Checking IP reputation from Cisco Talos")
# for ip in ip_list:
# url = "https://talosintelligence.com/reputation_center/lookup?search=" + ip
# response = requests.request("GET", url).text
# if (
# "This IP address has been observed to be associated with malicious activity."
# in response
# ):
# logging.info("IP: " + ip + " is malicious")
# # self.bad_ip_list.append(ip)
# else:
# logging.info("IP: " + ip + " is not malicious")


# # ==================
Expand Down
2 changes: 1 addition & 1 deletion hackalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def accept_user_input():

# Invoke VT IP Checker module
vtip_results = ip_checker.checkIPReputationVT(args.ip)
logging.info("Virus Total results: ", vtip_results)
# logging.info("Virus Total results: ", vtip_results)

# Invoke OTX IP Checker module
# otx_results = ...
Expand Down

2 comments on commit bc07314

@H4ppy-04
Copy link
Collaborator

Choose a reason for hiding this comment

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

We love a good lint. Also nice fix.

@initd1
Copy link
Owner

@initd1 initd1 commented on bc07314 Apr 11, 2023

Choose a reason for hiding this comment

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

Thanks!

Please sign in to comment.