I'm trying to sniff ospf packet in Python, and have achieve this aim in ubuntu.
When it comes to windows, I could only sniff TCP, UDP and IGMP packets.I can capture ospf packets by wireshark.
The code is below.
from socket import *
local_name = getfqdn(gethostname())
local_addr = gethostbyname(local_name)
sniffer = socket(AF_INET, SOCK_RAW, IPPROTO_IP)
sniffer.setsockopt(IPPROTO_IP, IP_HDRINCL, 1)
pkt = sniffer.recvfrom(2048)
ipHeader = pkt[0:20]
ip_hdr = struct.unpack("!9s1s10s",ipHeader)
sniffer = socket(PF_PACKET,SOCK_RAW,htons(0x0800))
I find out the reason. It seems that ospf packet only can be sniffed by capturing ethernet frame in the data link layer. But in windows, that is forbidden. Winpcap could be used.