I am working on a small IP address scanner, and am running into issues with the results from .poll()
. I get a return from what I'm assuming is the router, so I get a 0 either way. I would've commented on a different post but I don't have the rep. So how can I check these results in a way that takes this into account?
import subprocess
from netaddr import *
import os
hosts = []
for ip in IPNetwork('192.168.14.157/22'):
hosts.append(ip)
p = subprocess.Popen('ping ' + str(ip))
p.wait()
print(p.poll())
idle output looks pretty much like:
0
1
0
0
3221225786 <When I exit a prompt before stopping the program
and cmd outputs are:
Pinging 192.168.12.5 with 32 bytes of data:
Reply from 192.168.14.157: Destination host unreachable.
Reply from 192.168.14.157: Destination host unreachable.
Reply from 192.168.14.157: Destination host unreachable.
Reply from 192.168.14.157: Destination host unreachable.
and
Pinging 192.168.12.1 with 32 bytes of data:
Reply from 192.168.12.1: bytes=32 time=9ms TTL=64
Reply from 192.168.12.1: bytes=32 time=9ms TTL=64
Reply from 192.168.12.1: bytes=32 time=7ms TTL=64
Reply from 192.168.12.1: bytes=32 time=7ms TTL=64