python
import subprocess
def is_reachable(ip_address):
result = subprocess.call(['ping', '-c', '3', ip_address])
if result == 0:
return f"{ip_address} is OK"
else:
return f"{ip_address} is not OK"
with open('ip_addresses.txt', 'r') as file:
ip_addresses = file.readlines()
for ip in ip_addresses:
print(is_reachable(ip.strip()))
shell
#!/bin/bash
while IFS= read -r ip; do
ping -c 3 $ip
if [ $? -eq 0 ]; then
echo "$ip is OK"
else
echo "$ip is not OK"
fi
done < "ip_addresses.txt"