Skip to content

Instantly share code, notes, and snippets.

@ujj-nuvo
Created January 8, 2016 17:24
Show Gist options
  • Save ujj-nuvo/bb7e040ab8cabc29541d to your computer and use it in GitHub Desktop.
Save ujj-nuvo/bb7e040ab8cabc29541d to your computer and use it in GitHub Desktop.
def recv_pkts(hdr, data):
packet = EthDecoder().decode(data)
ip_hdr = packet.child()
op_code = ip_hdr.get_ar_op()
src_mac = ip_hdr.as_hrd(ip_hdr.get_ar_sha())
dest_ip = ip_hdr.as_pro(ip_hdr.get_ar_spa())
print "ARP Request from Device : " + str(src_mac)
if __name__ == "__main__":
max_bytes = 1024 # number of bytes to capture per packet
promiscuous = False # When a data packet is transmitted in non-promiscuous mode, all the LAN devices "listen to" the data to determine if the network address included in the data packet is theirs
read_timeout = 100 # in milliseconds
pc = pcapy.open_live("en0", max_bytes, promiscuous, read_timeout)
packet_limit = 100
pc.setfilter("arp")
try:
pc.loop(packet_limit, recv_pkts) # capture packets
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment