title: Python Scapy Arp Scanning Subnet Script From a Book
body: <p>I am reading a Python book and in it there is a script to use scapy, the Python tool/module, to scan a subnet for any hosts that are up and report back their IP and MAC addresses. This script is an enhancement on a previous one that was calling <code>/usr/bin/arping</code>. That previous script only allowed one IP address at a time and was platform dependent on the <code>arping</code> tool being available. Apparently, this script (that does not work for me) is platform independent! </p>
  
  <p>If someone could look over the script and debug it that would be awesome. Here is the script: </p>
  
  <pre><code>#! /usr/bin/env python
  
  from scapy.all import srp
  from scapy.all import Ether, ARP, conf
  
  import sys
  
  def arping(iprange="10.0.1.0/24"):
      """Arping function takes IP Address or Network, returns nested mac/ip list"""
  
      #conf, verb = 0
      ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=iprange), timeout=2)
  
      collection = []
      for snd, rcv in ans:
          result = rcv.sprintf(r"%ARP.psrc% %Ether.src%").split()
          collection.append(result)
      return collection
  
  if __name__ == "__main__":
      if len(sys.argv) &gt; 1:
          for ip in sys.argv[1:]:
              print "arping", ip
              print arping(ip)
  
      else:
          print arping()
  </code></pre>
  
  <p>The script does not work. It just prints that it is scanning stuff but that nothing was found. </p>
  
  <p>I looked on this website and found a tutorial that also did not work. That website with the relevant content is here: <a href="http://www.secdev.org/projects/scapy/doc/usage.html#arp-ping" rel="nofollow">http://www.secdev.org/projects/scapy/doc/usage.html#arp-ping</a></p>
  
  <p>Please, see below for a sample of the output I obtain when running this script:</p>
  
  <pre><code>loser@loser:~/Desktop/pyFun2$ gedit arp_scanz.py
  loser@loser:~/Desktop/pyFun2$ sudo python arp_scanz.py
  WARNING: No route found for IPv6 destination :: (no default route?)
  Begin emission:
  Finished to send 256 packets.
  
  Received 0 packets, got 0 answers, remaining 256 packets
  []
  </code></pre>
  
  <p>Does anyone out there know what I am missing? </p>
  
  <p><strong>UPDATE - SOLUTION</strong>
  change the srp function or method call to specify the exact interface to scan on like so:</p>
  
  <pre><code>ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=iprange),iface="en1", timeout=2)
  </code></pre>