Ping_Python Below is Code to ping hosts and create a CSV file out of the results.
import os
for i in range (0,255):
for j in range(1,254):
hostname = "10.222.{0}.{1}".format(i,j)
response = os.system ("ping -n 1 " + hostname)
if response == 0:
fp = open("C:\\Users\\anudeepa\\Desktop\\hostname.csv", 'w')
fp.writelines(hostname + "host up\n")
else:
fp = open("C:\\Users\\anudeepa\\Desktop\\hostname.csv", 'w')
fp.write(hostname + "host dead\n")
This code allows me to ping hosts,but while writing the results to a CSV, it overwrites the previously written result and only writes penultimate or unltimate result.