# required import statements
import sys
import requests
import socket
import json

# Check to see if there are the correct number of command line parameters (two arguments)
if len(sys.argv) < 2:
    # If not 2, then print the error message to explain how to use it
    print("Usage: " + sys.argv[0] + " <url>")
    sys.exit(1)

# Get the headers from the site using the address/domain which will be the first command line argument and print it
req = requests.get("https://" + sys.argv[1])
print("\n" + str(req.headers))

# Get the host name using the socket module, then print the IP address
gethostby_ = socket.gethostbyname(sys.argv[1])
print("\nThe IP address of " + sys.argv[1] + " is: " + gethostby_ + "\n")

# API we will be using ipinfo.io
# Second request to get information about the IP address using the API. The extention will return the info in json format
req_two = requests.get("https://ipinfo.io/" + gethostby_ + "/json")
resp_ = json.loads(req_two.text)

# Printing the location, region, city, and country information of the IP address
print("Location: " + resp_['loc'])
print("Region: " + resp_['region'])
print("City: " + resp_['city'])
print("Country: " + resp_['country'])
