Python Forum

Full Version: [split] Function / Arguments / Error Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My mistake, and you different, my code running on a Windows system reported error, and there is No Way Out. The error is: OSError: [WinError 10022]

import socket, sys, time, os

def tcpsniffer():
	s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
	
	while True:
		packet = s.recvfrom(1024)
		print('recvfrom packet!')

if __name__ == '__main__':
	tcpsniffer()
(Dec-21-2021, 09:55 AM)buran Wrote: [ -> ]I would suggest https://realpython.com/python-sockets/
but it is ok on linux os, such as ubuntu.
(Dec-21-2021, 09:55 AM)buran Wrote: [ -> ]I would suggest https://realpython.com/python-sockets/
hello
recently, when I porting my python code from linux os to windows7, the code running is error, the error is WINerror 10022,but the error is strange. so you know what,please.
the code is:
import socket as s
fd = s.socket(s.AF_INET, s.SOCK_RAW, s.IPPROTO_TCP)
fd.recvfrom(1024)
shouldn't you bind to host/port and then listen (in case of server) or connect (in case of client)?
i.e. I don't think this will work on Linux (as you claim)

Also check if this will help https://stackoverflow.com/q/62281097/4046632
From the link in the answer it says that on some Windows OS `A call to the bind function with a raw socket for the IPPROTO_TCP protocol is not allowed", so my question about bind may not be 100 percent correct.