I am learning Python and one thing I thought I could work on was a program to scan an IP range and then compare the results with previous - alerting me to any new IP addresses that respond to ping.
Can I get some feedback on my code? Is there a better way? Is there a more Pythonic way?
All it does so far is scan a range and build a list of IPs that replied to ping.
Any help will be appreciated.
Gene
import os
hosts = []
subnet= "10.0.0."
for host in range (1,4):
ip = subnet + str(host)
ping_cmd = "ping -c1 -w1 " + ip + " > /dev/null"
responce = os.system(ping_cmd)
if responce == 0:
print(ip +" is live")
hosts.append(ip)
else:
print(ip + " is dead")
print hosts