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
# import module from pythonping import ping # pinging the host 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
# import modules from tkinter import * from pythonping import ping def get_ping(): result = ping(e.get(), verbose = True ) res. set (result) # object of tkinter # and background set for light grey master = Tk() master.configure(bg = 'light grey' ) # Variable Classes in tkinter res = StringVar() # Creating label for each information # name using widget Label 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) # Creating label for class variable # name using widget Entry Label(master, text = " ", textvariable=res, bg=" light grey").grid( row = 1 , column = 1 , sticky = W) e = Entry(master) e.grid(row = 0 , column = 1 ) # creating a button using the widget # Button that will call the submit function b = Button(master, text = "Show" , command = get_ping) b.grid(row = 0 , column = 2 , columnspan = 2 , rowspan = 2 , padx = 5 , pady = 5 ) mainloop() |
Output: