File size: 4,453 Bytes
a3acd70
b43f4c5
45a9528
 
0a58343
 
 
3a8824c
0a58343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a8824c
 
0a58343
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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()