How to open a socket to send a python tcp packet

I need to use the handles to collect a tcp packet (SYN) and send it to the server. How to properly open a socket so that you don't have to collect packets at lower levels. I write on ubuntu 18.04

I open it like this, but I'm not sure what is correct: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)

Author: Cheeeesy, 2020-05-03

2 answers

Set scapy

ip=IP(src="192.168.0.2",dst="192.168.0.1")  
SYN=TCP(sport=40508,dport=40508,flags="S",seq=12345)
send(ip/SYN)

A simple package constructor, and sends it with a single command. Ready SYN scanner

 0
Author: eri, 2020-05-03 10:28:23

Eri's answer helped, you can look at the documentation and this article helped https://medium.com/@NickKaramoff/tcp-packets-from-scratch-in-python-3a63f0cd59fe

 0
Author: Cheeeesy, 2020-05-04 16:27:11