gibiee commited on
Commit
bd628f6
·
1 Parent(s): 077aa2e
Files changed (1) hide show
  1. app.py +34 -4
app.py CHANGED
@@ -1,7 +1,37 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import socket
3
 
4
+ def check(ip, port) :
5
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s :
6
+ resp = s.connect_ex((ip, int(port)))
7
 
8
+ if resp == 0 :
9
+ return 'Opened'
10
+ elif resp == 10061 :
11
+ return 'Opened but nothing'
12
+ elif resp == 10060 :
13
+ return 'Closed'
14
+ else :
15
+ return "Unknown"
16
+
17
+ with gr.Blocks() as demo :
18
+ gr.Markdown("""
19
+ # Port Checker
20
+ ### Output will be returned one of the 4 states.
21
+ ① Opened
22
+ ② Opened but nothing
23
+ ③ Closed
24
+ ④ Unknown
25
+ """)
26
+ with gr.Row() :
27
+ with gr.Column() :
28
+ input_ip = gr.Text(label='ip', value="127.0.0.1")
29
+ input_port = gr.Text(label='port', value="80")
30
+ btn = gr.Button(value="Check", variant='primary')
31
+
32
+ with gr.Column() :
33
+ output_state = gr.Text(label='state', interactive=False)
34
+
35
+ btn.click(fn=check, inputs=[input_ip, input_port], outputs=output_state)
36
+
37
+ demo.launch()