I want to create a raw socket in Windows to connect to a specific interface on my laptop. I have it working on Linux but it does not work in Windows.
This is my code that is fine in Linux but not in Windows:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
#s.bind(("192.168.1.100", 0))
s.bind((socket.gethostname(), 0))
#s.bind((socket.gethostbyname(socket.gethostname()), 0))
The commented out lines are suggestions I found here: Python Raw Socket to Ethernet Interface (Windows) but they did not work for me. I always get this error:
Traceback (most recent call last):
File "D:/raw_socket.py", line 5, in <module>
s.bind((socket.gethostname(), 0))
OSError: [WinError 10022] An invalid argument was supplied
I was unable to find a solution while researching this problem. Any help is highly appreciated.