1import os
2
3ip_list = ['8.8.8.8']
4for ip in ip_list:
5 response = os.popen(f"ping {ip}").read()
6 if "Received = 4" in response:
7 print(f"UP {ip} Ping Successful")
8 else:
9 print(f"DOWN {ip} Ping Unsuccessful")
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
1st = Speedtest()
2 print("Download:=>", st.download())
3 print("upload:=>", st.upload())
4 st.get_servers([])
5 print("Ping :=>", st.results.ping)