-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_headers.py
45 lines (37 loc) · 1.7 KB
/
http_headers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Library: HTTP Headers
Author: Haluk YAMANER
Email: [email protected]
Web: https://www.halukyamaner.com
Version: 1.0
Description:
HTTP Headers is a simple Python library that retrieves and displays HTTP response headers from a specified
web domain. It is an essential tool for web developers and security analysts, providing insights into
the headers that web servers send, which are crucial for security, compliance, and debugging purposes.
Usage:
The script is run from the command line. Upon execution, users are prompted to enter a web domain
(without http/https), and the script prepends the necessary protocols to make a secure HTTP request.
It then fetches and displays the headers in a clear, readable format.
Requirements:
Python 3.x
Modules: requests
Features:
- Simple and intuitive user interface that asks for domain input and displays HTTP headers.
- Automatically formats and prints the response headers for easy analysis.
- Includes error handling for unreachable domains or network issues.
- Provides detailed information about each header, aiding in educational and troubleshooting efforts.
"""
import requests
# Ask the user for the domain without http/https
domain = input("Please enter the website domain (without http:// or https://): ")
# Automatically prepend https:// to the domain
url = f"https://{domain}"
try:
# Make a request to the URL
response = requests.get(url)
# Print the headers in a human-readable format
print("\nHTTP Response Headers:\n")
for key, value in response.headers.items():
print(f"{key}: {value}")
except requests.exceptions.RequestException as e:
print(f"Failed to reach {url}. Error: {e}")