import streamlit as st import requests import whois import socket import ssl from bs4 import BeautifulSoup from datetime import datetime def get_ssl_expiry_date(hostname): try: context = ssl.create_default_context() with socket.create_connection((hostname, 443)) as sock: with context.wrap_socket(sock, server_hostname=hostname) as ssock: ssl_info = ssock.getpeercert() expire_date = datetime.strptime(ssl_info['notAfter'], '%b %d %H:%M:%S %Y %Z') days_left = (expire_date - datetime.utcnow()).days return days_left except Exception as e: return None def main(): st.title("Website Analysis Tool") url = st.text_input("Enter the website URL (e.g., https://www.example.com)") if st.button("Analyze") and url: if not url.startswith("http"): url = "http://" + url try: response = requests.get(url) status_code = response.status_code # Basic SEO Analysis soup = BeautifulSoup(response.content, 'html.parser') title = soup.title.string if soup.title else "No title tag found" meta_desc = soup.find('meta', attrs={'name': 'description'}) meta_desc_content = meta_desc['content'] if meta_desc else "No meta description found" # WHOIS Information domain = url.replace("http://", "").replace("https://", "").split('/')[0] domain_info = whois.whois(domain) # SSL Certificate Check ssl_days_left = get_ssl_expiry_date(domain) if ssl_days_left is not None: ssl_status = f"SSL Certificate expires in {ssl_days_left} days" else: ssl_status = "No SSL Certificate found" # Security Headers Check security_score = 0 headers = response.headers if 'X-Frame-Options' in headers: security_score += 10 if 'X-Content-Type-Options' in headers: security_score += 10 if 'Content-Security-Policy' in headers: security_score += 10 if 'Strict-Transport-Security' in headers: security_score += 10 if 'Referrer-Policy' in headers: security_score += 10 # Overall Score Calculation total_score = security_score if title != "No title tag found": total_score += 20 if meta_desc_content != "No meta description found": total_score += 20 if ssl_days_left is not None: total_score += 20 st.subheader("SEO Analysis") st.write(f"**Title Tag:** {title}") st.write(f"**Meta Description:** {meta_desc_content}") st.subheader("Security Analysis") st.write(f"**SSL Status:** {ssl_status}") st.write("**Security Headers:**") for header in ['X-Frame-Options', 'X-Content-Type-Options', 'Content-Security-Policy', 'Strict-Transport-Security', 'Referrer-Policy']: if header in headers: st.write(f"- {header}: {headers[header]}") else: st.write(f"- {header}: Not Found") st.subheader("WHOIS Information") st.write(f"**Domain Name:** {domain_info.domain_name}") st.write(f"**Registrar:** {domain_info.registrar}") st.write(f"**Creation Date:** {domain_info.creation_date}") st.write(f"**Expiration Date:** {domain_info.expiration_date}") st.subheader("Overall Score") st.write(f"**Total Score:** {total_score} / 100") st.subheader("Suggestions for Improvement") if title == "No title tag found": st.write("- Add a title tag to your homepage.") if meta_desc_content == "No meta description found": st.write("- Add a meta description to your homepage.") if ssl_days_left is None: st.write("- Install an SSL certificate to secure your site with HTTPS.") for header in ['X-Frame-Options', 'X-Content-Type-Options', 'Content-Security-Policy', 'Strict-Transport-Security', 'Referrer-Policy']: if header not in headers: st.write(f"- Add the {header} header to improve security.") except Exception as e: st.error(f"An error occurred: {e}") if __name__ == "__main__": main()