Python Forum
[split] Function / Arguments / Error Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Function / Arguments / Error Help
#1
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()
Reply
#2
I would suggest https://realpython.com/python-sockets/
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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.
Reply
#4
(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)
buran write Dec-22-2021, 08:37 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#5
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020