Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python socket setsockopt with raw socket

Just send tcp_syn with python socket raw. I follow the code here, but when I run the code I got below error:

Traceback (most recent call last):
  File "findPort.py", line 122, in <module>
    s.sendto(packet, (dest_ip , 27015 ))    # put this in a loop if you want to flood the target
socket.error: [Errno 22] Invalid argument

However, when I delete setsockopt:

#s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

the code run smoothly. Unfortunately, as you can image, the wireshark sniff two tcp header data. one is the kernel add the other is myself add.

So the question is :

  1. what does the error mean as I show above?
  2. why I delete setsockopt the error disappear?
  3. how can I send tcp_syn with python 2.7?

thanks so much in advance~~~~~~

like image 296
Courage Avatar asked May 02 '26 12:05

Courage


1 Answers

Let me answer my own question. The main reason why python can not send raw socket because Mac/Windows not support customize TCP/UDP header. If you want to write your own TCP/UDP header and send it to net, you need to use LINUX operation system.

like image 116
Courage Avatar answered May 04 '26 02:05

Courage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!