File size: 1,867 Bytes
81eb702
 
1c2cfc6
be8ed5e
81eb702
 
 
 
9a95c17
 
 
 
81eb702
9a95c17
81eb702
1c2cfc6
9a95c17
1c2cfc6
9a95c17
 
1c2cfc6
 
 
 
 
9a95c17
1c2cfc6
9a95c17
be8ed5e
1c2cfc6
9a95c17
 
 
1c2cfc6
 
9a95c17
 
 
 
1c2cfc6
d24397c
 
 
 
 
 
 
 
1c2cfc6
 
 
 
 
 
 
 
 
 
 
 
 
be8ed5e
d24397c
 
 
 
 
be8ed5e
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
import os
import socket

def fetch_url(url):
    try:
        r = requests.get(url, timeout=5)
        status = str(r.status_code)
        headers = str(dict(r.headers))
        body = r.text[:2000]
        return "Status: " + status + "\nHeaders: " + headers + "\nBody:\n" + body
    except Exception as e:
        return "Error: " + str(e)

def get_env():
    lines = []
    for k, v in sorted(os.environ.items()):
        lines.append(k + "=" + v[:100])
    return "\n".join(lines)

def net_info():
    hostname = socket.gethostname()
    try:
        ip = socket.gethostbyname(hostname)
    except Exception:
        ip = "unknown"
    parts = ["Hostname: " + hostname, "IP: " + ip]
    try:
        with open("/etc/resolv.conf") as f:
            parts.append("resolv.conf:\n" + f.read())
    except Exception:
        pass
    try:
        with open("/etc/hosts") as f:
            parts.append("hosts:\n" + f.read())
    except Exception:
        pass
    return "\n".join(parts)


def read_file(path):
    try:
        with open(path, 'r') as f:
            return f.read()[:5000]
    except Exception as e:
        return 'Error: ' + str(e)

with gr.Blocks() as demo:
    with gr.Tab("Fetch"):
        url_in = gr.Textbox(label="url")
        url_out = gr.Textbox(label="output")
        url_in.submit(fetch_url, url_in, url_out)
    with gr.Tab("Env"):
        env_btn = gr.Button("Get Env")
        env_out = gr.Textbox(label="env")
        env_btn.click(get_env, None, env_out)
    with gr.Tab("Net"):
        net_btn = gr.Button("Get Net Info")
        net_out = gr.Textbox(label="net")
        net_btn.click(net_info, None, net_out)

    with gr.Tab("File"):
        file_in = gr.Textbox(label="path")
        file_out = gr.Textbox(label="content")
        file_in.submit(read_file, file_in, file_out)

demo.launch()