summaryrefslogtreecommitdiffstats
path: root/cap.py
diff options
context:
space:
mode:
authorTomek Dubrownik <t.dubrownik@gmail.com>2012-01-26 19:58:09 +0100
committerTomek Dubrownik <t.dubrownik@gmail.com>2012-01-26 19:58:09 +0100
commitae406076f7a5691a9922a9b66d29c29f03fb2892 (patch)
tree8125cfb8fe2506e50a128e1593c8f19bfd32d673 /cap.py
downloadcheckinator-ae406076f7a5691a9922a9b66d29c29f03fb2892.tar.gz
checkinator-ae406076f7a5691a9922a9b66d29c29f03fb2892.tar.bz2
checkinator-ae406076f7a5691a9922a9b66d29c29f03fb2892.zip
initial commit
Diffstat (limited to 'cap.py')
-rw-r--r--cap.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/cap.py b/cap.py
new file mode 100644
index 0000000..7651e6c
--- /dev/null
+++ b/cap.py
@@ -0,0 +1,30 @@
+import logging
+import pcapy
+import struct
+
+interface = 'wlan0'
+target = './dhcp-cap'
+logger = logging.getLogger()
+logger.setLevel(logging.DEBUG)
+logger.addHandler(logging.StreamHandler())
+
+def hwaddr_ascii(packet):
+ # picking up MAC directly from ethernet frame
+ return ':'.join('%02x' % ord(c) for c in packet[6:12])
+
+def capture_dhcp(itf):
+ f = open(target, 'w')
+ reader = pcapy.open_live(itf, 4096, False, 5000)
+ reader.setfilter('udp dst port 67')
+ def callback(header, packet):
+ hwaddr = hwaddr_ascii(packet)
+ logger.info('Captured dhcp request from %s', hwaddr)
+ f.write(hwaddr + '\n')
+ f.flush()
+ try:
+ while True:
+ reader.dispatch(1, callback)
+ except KeyboardInterrupt:
+ pass
+
+capture_dhcp('wlan0')