You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import requests
|
|
import subprocess
|
|
import socket
|
|
|
|
def trace_route(ip_address):
|
|
traceroute = subprocess.Popen(["traceroute", ip_address], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
trace_output, _ = traceroute.communicate()
|
|
return trace_output.decode('utf-8')
|
|
|
|
def resolve_hostname(hostname):
|
|
return socket.gethostbyname(hostname)
|
|
|
|
def send_http_request(url):
|
|
try:
|
|
response = requests.get(url)
|
|
return response.status_code, response.headers
|
|
except requests.RequestException as e:
|
|
return None, str(e)
|
|
|
|
|
|
def main():
|
|
url = input("Enter URL to trace: ")
|
|
|
|
try:
|
|
hostname = url.split('/')[2] # Extract hostname from URL
|
|
ip_address = resolve_hostname(hostname)
|
|
|
|
print(f"Tracing route to {hostname} [{ip_address}]")
|
|
trace_output = trace_route(ip_address)
|
|
print(trace_output)
|
|
|
|
status_code, headers = send_http_request(url)
|
|
if status_code:
|
|
print(f"\nHTTP Response from {url}:")
|
|
print(f"Status code: {status_code}")
|
|
print("Headers:")
|
|
for header, value in headers.items():
|
|
print(f"{header}: {value}")
|
|
else:
|
|
print(f"\nFailed to retrieve HTTP response: {headers}")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {str(e)}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|