title: Pinging an IP range with Scapy
body: <p>I'm attempting to write a Python script which uses the Scapy module to ping an internal IP range to determine which IP's are online. I've got this so far:</p>
  
  <pre><code>#!/usr/bin/python
  from scapy.all import *
  conf.verb = 0
  for ip in range(0, 256):
      packet = IP(dst="192.168.0." + str(ip), ttl=20)/ICMP()
      reply = sr1(packet)
      if "192.168." in reply.src:
           print reply.src, "is online"
  </code></pre>
  
  <p>And the program will sit for a while doing nothing, and then if I kill it with CTRL+C I get an error message:</p>
  
  <pre><code>Traceback (most recent call last):
  File "sweep.py", line 7, in &lt;module&gt;
  if "192.168." in reply.src:
  AttributeError: 'NoneType' object has no attribute 'src'
  </code></pre>
  
  <p>However if I try it with a single IP address, instead of a range, it works. Like this:</p>
  
  <pre><code>#!/usr/bin/python
  from scapy.all import *
  conf.verb = 0
  packet = IP(dst="192.168.0.195", ttl=20)/ICMP()
  reply = sr1(packet)
  if "192.168." in reply.src:
      print reply.src, "is online"
  </code></pre>
  
  <p>Anyone know how I can fix this problem? Or do you have any other ideas on how I can ping an IP range with Scapy, to determine which hosts are online?</p>