. Advertisement .
..3..
. Advertisement .
..4..
I need to check if my system’s web accessibility is working properly. I want to follow the way of using IP. How To Ping IP Using Python?
The ‘ping‘ utility is pre-installed in all Windows as well as Linux system. The idea is to create a script that runs the ‘ping’ program via a terminal or command prompt. Here are some ways that you can adapt flexibly according to your device.
Method 1: Using the following command:
ping -c 4 <ip_address>
The -c can be used to stop after n count.
Method 2: Ping using os command
Here is example:
import os
ip_list = ['8.8.8.8']
for ip in ip_list:
response = os.popen(f"ping {ip}").read()
if "Received = 4" in response:
print(f"UP {ip} Ping Successful")
else:
print(f"DOWN {ip} Ping Unsuccessful")
Here is the quick fix for this topic