Build a GUI Application to ping the host using Python
Last Updated :
04 Dec, 2021
Prerequisite: Python GUI – Tkinter
In this article, we are going to see how to ping the host with a URL or IP using the python ping module in Python. This module provides a simple way to ping in python. And It checks the host is available or not and measures how long the response takes.
“Before” starting we need to install this module into your system.
pip install pythonping
The GUI would look like below:
Syntax: ping(‘URL or IP’)
Parameter:
- verbose : enables the verbose mode, printing output to a stream
- timeout : is the number of seconds you wish to wait for a response, before assuming the target is unreachable
- payload : allows you to use a specific payload (bytes)
- size : is an integer that allows you to specify the size of the ICMP payload you desire
Code:
Python3
from pythonping import ping
ping( 'www.google.com' , verbose = True )
|
Output:
Reply from 142.250.71.4, 9 bytes in 61.09ms
Reply from 142.250.71.4, 9 bytes in 60.24ms
Reply from 142.250.71.4, 9 bytes in 60.22ms
Reply from 142.250.71.4, 9 bytes in 60.04ms
Reply from 142.250.71.4, 9 bytes in 61.09ms
Reply from 142.250.71.4, 9 bytes in 60.24ms
Reply from 142.250.71.4, 9 bytes in 60.22ms
Reply from 142.250.71.4, 9 bytes in 60.04ms
Round Trip Times min/avg/max is 60.04/60.4/61.09 ms
Implementation for GUI:
Pinging GUI Application with Tkinter
Python3
from tkinter import *
from pythonping import ping
def get_ping():
result = ping(e.get(), verbose = True )
res. set (result)
master = Tk()
master.configure(bg = 'light grey' )
res = StringVar()
Label(master, text = "Enter URL or IP :" ,
bg = "light grey" ).grid(row = 0 , sticky = W)
Label(master, text = "Result :" , bg = "light grey" ).grid(row = 1 , sticky = W)
Label(master, text = " ", textvariable=res, bg=" light grey").grid(
row = 1 , column = 1 , sticky = W)
e = Entry(master)
e.grid(row = 0 , column = 1 )
b = Button(master, text = "Show" , command = get_ping)
b.grid(row = 0 , column = 2 , columnspan = 2 , rowspan = 2 , padx = 5 , pady = 5 )
mainloop()
|
Output:
Share your thoughts in the comments
Please Login to comment...