File size: 2,746 Bytes
6136670
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
930eb8a
6136670
 
 
930eb8a
6136670
 
 
 
47cf481
6136670
 
 
 
 
 
 
 
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
import gradio as gr
import requests
from getStatus import run  # Assuming this module contains the run function

def getURL(URL):
    if URL.startswith("http://") or URL.startswith("https://"):
        websiteUrl = URL
    else:
        websiteUrl = "http://" + URL
    return websiteUrl

def setHeaders(websiteUrl):
    try:
        URL = getURL(websiteUrl)
        web_response = requests.get(URL, timeout=5)
        user_agent = web_response.request.headers['User-Agent']
        headers = {'User-Agent': user_agent}
        return headers
    except requests.RequestException as e:
        print(f"Error fetching headers: {e}")
        return None

def websiteStatus(websiteUrl, user_agent_choice):
    try:
        URL = getURL(websiteUrl)
        
        if user_agent_choice == "Your Browser Headers":
            headers = setHeaders(websiteUrl)
        else:
            headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
        
        web_response = requests.get(URL, headers=headers)
        web_status = str(web_response.status_code)
        code, webstatus, status, morestatus = run(web_status)
        print(f"Processed Output: {code}, {webstatus}, {status}, {morestatus}")  # Debug print
        return code, webstatus, status, morestatus
    
    except requests.ConnectionError:
        error = f"Failed to connect to {websiteUrl}"
        return error, error, error, error
    except requests.Timeout:
        error = f"Request to {websiteUrl} timed out"
        return error, error, error, error
    except requests.RequestException as e:
        error = f"An error occurred: {e}"
        return error, error, error, error

# Create a Gradio interface
app = gr.Interface(
    fn=websiteStatus,
    inputs = [
        gr.Textbox(label="Enter URL", placeholder="https://google.com", type="text"),
        gr.Radio(["Your Browser Headers", "Our Server Headers"], label="Select User Agent")
    ],
    outputs = [
        gr.Textbox(label="Code", type="text"),
        gr.Textbox(label="Server/Website Status", type="text"),
        gr.Textbox(label="Code Status", type="text"),
        gr.Textbox(label="More Code Status Information", type="text")
    ],
    title="Website HTTP Status Checker<br> by <a href='https://nayankasturi.eu.org'>Nayan Kasturi</a> aka Raanna.<br> Checkout my <a href='https://github.com/raannakasturi'>Github</a> for more projects and contact info.",
    description="This app scans the website for HTTP statuses.<br> Licenced under <a href='https://creativecommons.org/licenses/by-nc-sa/4.0/'>cc-by-nc-sa-4.0</a>",
    api_name="get",
    concurrency_limit=10
)

if __name__ == "__main__":
    app.launch()