-1

hi i want to sniff packets via python, ipv6 on FREEBSD.

i hard to trying googlings to get information but there is nothing for freebsd example.

below code is not working because someone says that bsd system does not supporting

socket.PF_PACKET.

Does anyone have any links to Help me?

s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(3))
s.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, struct.pack("%ds"%(len("em1")+1,),"em1"))
while condition:
    pkt = s.recvfrom(1500)
    addToQueue(filter(pkt))
user1500049
  • 993
  • 7
  • 15
osmund sadler
  • 1,021
  • 2
  • 15
  • 27

1 Answers1

2

I would take a look at using a Python wrapper for libpcap. libpcap is a C library that is used to sniff packets and process pcap dumps. This is the same library that Wireshark uses. It comes standard with OSX and can be installed on most Linux distributions.

There exists a number of Python wrapper for this:

Make sure to avoid any implementations that are pure Python, as they are not able to do packet sniffing.

Nathan Villaescusa
  • 17,331
  • 4
  • 53
  • 56