Manual for the PingClass

Here you can read how the ping class works and how to make a good use of it!

Why do we use the ping service

We try to make a good use of the ping service itself since it can help us before trying to open a socket and making any connection, just to see is the machine alive or maybe the IP address has changed in the mean time (e.g. somebody plugged out the device or it crashed or something happened and DHCP assigned it another dynamic IP address).

Creating the object from the PingClass [Ping(pingAddress)]

If one wants to create an object of the PingClass one would have to use the following command ping = PingClass.Ping(pingAddress), where pingAddress is a string with the IP address or host name of the device/machine we want to ping.

Pinging the host [ping(numberOfTries)]

If one wants to ping the host, the following function should be used, ping(numberOfTries), where numberOfTries is an integer value, with numberOfTries you define how many times you want to try to ping the host. The first successful received ping is considered as an "alive sign" from the host and it stops pinging anymore, in the case if numberOfTries > 1. The function responds with an integer value:

1, if the host that we ping is alive (i.e. the host is OK and alive)
0, if no ping response has been seen or the timeout happened (we have set up a timeout for the ping function to be 2 seconds)
2, if the host is unknown (e.g. a wrong IP address or host name)

Example code how to use it

Here you can see an example code how to use the ping class

import PingClass

machinePC = PingClass.Ping('') #makes the ping object with the following IP address:

isMachineAlive = #will try to ping it 3 times

if isMachineAlive == 1:
 print 'Machine alive and kicking'
elif isMachineAlive == 0:
 print 'No ping response from the machine'
 print 'Unknown host, check your host name or IP address'

Class code

You can find the PingClass code on the repository, inside of the file