Step 1: Create a file with name "ipFile" and insert all the IP's line by line
Step 2: Create a file checkConnectivity.py with below code
import os
import sys
with open('output','w+') as o:
o.write("Check hostname is accessible or not from file ipFile\n")
with open('ipFile',mode='r') as f:
for line in f:
hostname=line
#and then check the response...
with open('output','a+') as out:
response = os.system("ping -w 2 -c 2 " + hostname)
if response == 0:
out.write(hostname.split()[0] + " is accessible\n")
else:
out.write(hostname.split()[0] + " is not accessible\n")
Step 3: Run above file using command : python checkConnectivity.py
Step 4 : A new file with name "output" will be created with the details
Step 2: Create a file checkConnectivity.py with below code
import os
import sys
with open('output','w+') as o:
o.write("Check hostname is accessible or not from file ipFile\n")
with open('ipFile',mode='r') as f:
for line in f:
hostname=line
#and then check the response...
with open('output','a+') as out:
response = os.system("ping -w 2 -c 2 " + hostname)
if response == 0:
out.write(hostname.split()[0] + " is accessible\n")
else:
out.write(hostname.split()[0] + " is not accessible\n")
Step 3: Run above file using command : python checkConnectivity.py
Step 4 : A new file with name "output" will be created with the details
Comments
Post a Comment