Created
January 7, 2010 08:09
-
-
Save oraccha/271079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Packet sniffer by using PF_PACKET. | |
# Copyright (c) 2010 oraccha | |
import sys | |
from socket import * | |
ETH_P_IP = 0x800 | |
s = socket(PF_PACKET, SOCK_RAW, ETH_P_IP) | |
s.bind(("eth1", ETH_P_IP)) | |
while 1: | |
p = s.recv(2024) | |
plen = len(p) | |
# dump header | |
src = ":".join(["%02x" % ord(x) for x in p[0:6]]) | |
dst = ":".join(["%02x" % ord(x) for x in p[6:12]]) | |
type = ntohs(ord(p[12:13])) | |
print("%s > %s, ethertype %04x, length %d" % (src, dst, type, plen)) | |
# dump body | |
print("\t"), | |
for i in xrange(0, plen, 2): | |
print("%02x%02x" % (ord(p[i]), ord(p[i+1]))), | |
if i % 16 == 14: | |
print("\n\t"), | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment