Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while capturing packets from raw socket

Tags:

python

sockets

I am trying to run the following lines of program:

import socket
import struct
import binascii

sock = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(0x800))
print sock

I get the following error: Message File Name Line Position
Traceback
C:\Users\d\Documents\rawsocket.py 19
AttributeError: 'module' object has no attribute 'PF_PACKET'

I am using Pyscripter, Python 2.7 on windows 8.1

Thanks!

like image 513
abhinav singh Avatar asked Mar 31 '26 16:03

abhinav singh


1 Answers

you should use AF_INET on windows for opening raw sockets. something like:

sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
like image 60
Ankit Kumar Avatar answered Apr 02 '26 22:04

Ankit Kumar