import requests
def check_security_headers(url):
try:
response = requests.get(url)
headers = response.headers
security_headers = {
"Strict-Transport-Security": headers.get("Strict-Transport-Security"),
"X-Content-Type-Options": headers.get("X-Content-Type-Options"),
"X-Frame-Options": headers.get("X-Frame-Options"),
"X-XSS-Protection": headers.get("X-XSS-Protection"),
"Content-Security-Policy": headers.get("Content-Security-Policy"),
}
print(f"Security headers for {url}:")
for header, value in security_headers.items():
if value:
print(f" {header}: {value}")
else:
print(f" {header}: Not present")
except requests.exceptions.RequestException as e:
print(f"Error accessing '{url}': {e}")
if __name__ == "__main__":
target_url = input("Enter a URL to check security headers (e.g., http://example.com): ")
check_security_headers(target_url)