1import platform # For getting the operating system name
2import subprocess # For executing a shell command
3
4def ping(host):
5 """
6 Returns True if host (str) responds to a ping request.
7 Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
8 """
9
10 # Option for the number of packets as a function of
11 param = '-n' if platform.system().lower()=='windows' else '-c'
12
13 # Building the command. Ex: "ping -c 1 google.com"
14 command = ['ping', param, '1', host]
15
16 return subprocess.call(command) == 0