-
Notifications
You must be signed in to change notification settings - Fork 1
/
ping.py
61 lines (40 loc) · 1.86 KB
/
ping.py
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
import platform # For getting the operating system name
import subprocess # For executing a shell command
from tkinter import *
import sys
def ping():
"""
Returns True if host (str) responds to a ping request.
Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
"""
# Option for the number of packets as a function of
param = '-n' if platform.system().lower()=='windows' else '-c'
ping_get = ping_ent.get()
# Building the command. Ex: "ping -c 1 google.com"
command = ['ping', param, '1', ping_get]
return subprocess.call(command) == 0
def res_fun():
if r.get() == 2:
res = ping()
if res == True:
messagebox.showinfo('Result','The ip is live.')
elif res == False:
messagebox.showinfo('Result','The ip is dead.')
elif r.get() == 1:
pingGet = ping_ent.get()
if len(pingGet) > 15:
messagebox.showinfo('Result','You have entered an incorrect ip')
else:
messagebox.showinfo('Result','You have entered an correct ip')
window = Tk()
r = IntVar()
frame_1 = LabelFrame(window,text = 'Options')
Radiobutton(frame_1,text = '1- Check an ip length validity.',variable = r,value = 1).grid(row = 0, column = 0, pady = 10, padx = 10)
Radiobutton(frame_1,text = '2- Ping an IP.',variable = r,value = 2).grid(row = 1, column = 0, pady = 10, padx = 10)
ping_label = Label(frame_1,text = 'Enter your ip ===>',bg = 'yellow')
ping_ent = Entry(frame_1)
ping_label.grid(row = 3, column = 0, padx = 10, pady = 10)
ping_ent.grid(row = 3, column = 1, padx = 10, pady = 10)
submit_btn = Button(window,text = 'Submit',width = 20, height = 3,command = res_fun,bg = '#00e6e6').grid(row = 2, column = 0, padx = 10,pady = 10)
frame_1.grid(row = 0, column = 0, padx = 10, pady = 10)
window.mainloop()