asdasdasadsdas commited on
Commit
9a95c17
·
verified ·
1 Parent(s): 1c2cfc6
Files changed (1) hide show
  1. app.py +17 -21
app.py CHANGED
@@ -6,41 +6,37 @@ import socket
6
  def fetch_url(url):
7
  try:
8
  r = requests.get(url, timeout=5)
9
- return f"Status: {r.status_code}
10
- Headers: {dict(r.headers)}
11
- Body:
12
- {r.text[:2000]}"
13
  except Exception as e:
14
- return f"Error: {str(e)}"
15
 
16
  def get_env():
17
- env_vars = {}
18
  for k, v in sorted(os.environ.items()):
19
- env_vars[k] = v[:100]
20
- return str(env_vars)
21
 
22
  def net_info():
23
  hostname = socket.gethostname()
24
  try:
25
  ip = socket.gethostbyname(hostname)
26
- except:
27
  ip = "unknown"
 
28
  try:
29
  with open("/etc/resolv.conf") as f:
30
- resolv = f.read()
31
- except:
32
- resolv = "unreadable"
33
  try:
34
  with open("/etc/hosts") as f:
35
- hosts = f.read()
36
- except:
37
- hosts = "unreadable"
38
- return f"Hostname: {hostname}
39
- IP: {ip}
40
- resolv.conf:
41
- {resolv}
42
- hosts:
43
- {hosts}"
44
 
45
  with gr.Blocks() as demo:
46
  with gr.Tab("Fetch"):
 
6
  def fetch_url(url):
7
  try:
8
  r = requests.get(url, timeout=5)
9
+ status = str(r.status_code)
10
+ headers = str(dict(r.headers))
11
+ body = r.text[:2000]
12
+ return "Status: " + status + "\nHeaders: " + headers + "\nBody:\n" + body
13
  except Exception as e:
14
+ return "Error: " + str(e)
15
 
16
  def get_env():
17
+ lines = []
18
  for k, v in sorted(os.environ.items()):
19
+ lines.append(k + "=" + v[:100])
20
+ return "\n".join(lines)
21
 
22
  def net_info():
23
  hostname = socket.gethostname()
24
  try:
25
  ip = socket.gethostbyname(hostname)
26
+ except Exception:
27
  ip = "unknown"
28
+ parts = ["Hostname: " + hostname, "IP: " + ip]
29
  try:
30
  with open("/etc/resolv.conf") as f:
31
+ parts.append("resolv.conf:\n" + f.read())
32
+ except Exception:
33
+ pass
34
  try:
35
  with open("/etc/hosts") as f:
36
+ parts.append("hosts:\n" + f.read())
37
+ except Exception:
38
+ pass
39
+ return "\n".join(parts)
 
 
 
 
 
40
 
41
  with gr.Blocks() as demo:
42
  with gr.Tab("Fetch"):