Add requirements and docstrings
This commit is contained in:
@ -6,6 +6,7 @@ from app.query_normalisation import get_public_ip
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
"""Get arguments from user via the command line."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Query information about an IP address or domain name."
|
||||
)
|
||||
|
@ -5,17 +5,20 @@ import requests
|
||||
|
||||
|
||||
def get_ip_information(ipv4_address: ipaddress.IPv4Address) -> dict:
|
||||
"""Retrieves information about a given IPv4 address from IP-API.com."""
|
||||
api_endpoint = "http://ip-api.com/json/{}".format(ipv4_address)
|
||||
resp = requests.get(api_endpoint).json()
|
||||
return resp
|
||||
|
||||
|
||||
def get_autonomous_system_number(as_info: str) -> str:
|
||||
"""Parses AS number from provided AS information."""
|
||||
as_number = as_info.split(" ")[0]
|
||||
return as_number
|
||||
|
||||
|
||||
def get_prefix_information(autonomous_system: int) -> list:
|
||||
"""Retrieves prefix information about a given autonomous system."""
|
||||
api_endpoint = "https://api.hackertarget.com/aslookup/?q={}".format(
|
||||
str(autonomous_system)
|
||||
)
|
||||
|
@ -17,6 +17,7 @@ HEADER = """-----------------------------------------------
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function."""
|
||||
args = parse_args()
|
||||
if not args.noheader:
|
||||
print(HEADER)
|
||||
|
@ -4,6 +4,7 @@ from tabulate import tabulate
|
||||
|
||||
|
||||
def generate_prefix_string(prefixes: list) -> str:
|
||||
"""Generate a string that spilts prefixes into rows of 5."""
|
||||
n = 4
|
||||
try:
|
||||
ret = ""
|
||||
@ -15,4 +16,5 @@ def generate_prefix_string(prefixes: list) -> str:
|
||||
|
||||
|
||||
def print_table(table_data) -> None:
|
||||
"""Print table generated by tabulate."""
|
||||
print(tabulate(table_data))
|
||||
|
@ -6,6 +6,7 @@ import socket
|
||||
|
||||
|
||||
def is_ip_address(query: str) -> bool:
|
||||
"""Verifies if a given query is a valid IPv4 address."""
|
||||
try:
|
||||
ipaddress.ip_address(query)
|
||||
return True
|
||||
@ -14,6 +15,7 @@ def is_ip_address(query: str) -> bool:
|
||||
|
||||
|
||||
def resolve_domain_name(domain_name: str) -> ipaddress.IPv4Address:
|
||||
"""Resolve a domain name via DNS or return None."""
|
||||
try:
|
||||
ip = socket.gethostbyname(domain_name)
|
||||
except socket.gaierror:
|
||||
@ -22,5 +24,6 @@ def resolve_domain_name(domain_name: str) -> ipaddress.IPv4Address:
|
||||
|
||||
|
||||
def get_public_ip() -> ipaddress.IPv4Address:
|
||||
"""Get the user's current public IPv4 address."""
|
||||
ip = requests.get("https://api.ipify.org").text
|
||||
return ip
|
||||
|
Reference in New Issue
Block a user