Fix Sonar issue, formatting (#99)
* Fix Sonar issue, formatting * Remove dev dependencies from requirements.tzt * Fix unit test failure
This commit is contained in:
33
app/main.py
33
app/main.py
@ -5,14 +5,13 @@
|
||||
import sys
|
||||
|
||||
from app.args import parse_args
|
||||
from app.print_table import print_table, generate_prefix_string
|
||||
from app.query_normalisation import is_ip_address, resolve_domain_name
|
||||
from app.ip_info import (
|
||||
get_ip_information,
|
||||
get_autonomous_system_number,
|
||||
get_ip_information,
|
||||
get_prefix_information,
|
||||
)
|
||||
|
||||
from app.print_table import generate_prefix_string, print_table
|
||||
from app.query_normalisation import is_ip_address, resolve_domain_name
|
||||
|
||||
HEADER = """-----------------------------------------------
|
||||
| IP Address Information Lookup Tool (iPilot) |
|
||||
@ -20,16 +19,14 @@ HEADER = """-----------------------------------------------
|
||||
-----------------------------------------------\n"""
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
"""Main function."""
|
||||
args = parse_args()
|
||||
if not args.noheader:
|
||||
print(HEADER)
|
||||
|
||||
# Set IP to passed IP address, or resolve passed domain name to IPv4
|
||||
ip_address = (
|
||||
resolve_domain_name(args.query) if not is_ip_address(args.query) else args.query
|
||||
)
|
||||
ip_address = resolve_domain_name(args.query) if not is_ip_address(args.query) else args.query
|
||||
|
||||
# If not given an IPv4, and can't resolve to IPv4, then throw error and exit
|
||||
if not ip_address:
|
||||
@ -37,22 +34,22 @@ def main():
|
||||
sys.exit(1)
|
||||
|
||||
# Get information from API
|
||||
ip_info = get_ip_information(ip_address)
|
||||
ip_info: dict | None = get_ip_information(ip_address)
|
||||
if not ip_info:
|
||||
print("ERROR: could not retrieve IP information from API.")
|
||||
sys.exit(1)
|
||||
as_number = get_autonomous_system_number(ip_info.get("as"))
|
||||
as_number: str = get_autonomous_system_number(ip_info["as"])
|
||||
|
||||
# Assemble list for table generation
|
||||
country = ip_info.get("country")
|
||||
region = ip_info.get("regionName")
|
||||
city = ip_info.get("city")
|
||||
table_data = [
|
||||
["IP Address", ip_info.get("query")],
|
||||
["Organization", ip_info.get("org")],
|
||||
country: str = ip_info["country"]
|
||||
region: str = ip_info["regionName"]
|
||||
city: str = ip_info["city"]
|
||||
table_data: list = [
|
||||
["IP Address", ip_info["query"]],
|
||||
["Organization", ip_info["org"]],
|
||||
["Location", f"{country}/{region}/{city}"],
|
||||
["Timezone", ip_info.get("timezone")],
|
||||
["Internet Service Provider", ip_info.get("isp")],
|
||||
["Timezone", ip_info["timezone"]],
|
||||
["Internet Service Provider", ip_info["isp"]],
|
||||
["Autonomous System", as_number],
|
||||
]
|
||||
|
||||
|
Reference in New Issue
Block a user