How to create Tcp, ip and Udp packages in Python?

Can someone tell me what is the main step for creating UDP, TCP and IP packets. And how can I generate it using Python?

+6
source share
2 answers

as suggested by jokeysmurf, you can create packages with scapy

if you want to send / receive regular packets, then you should use a socket or server sockets

to send TCP to port 80 google use

import socket HOST = 'google.com' # The remote host PORT = 80 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send('GET / HTTP/1.1\r\nHost: google.com\r\n\r\n') data = s.recv(1024) s.close() print 'Received', repr(data) 

to make it udp change SOCK_STREAM to SOCK_DGRAM

+8
source

You can do interactive packet processing with scapy .

In this article, you will start by gluing an IP packet.

Building a tcp package is as simple as:

packet = IP(src="10.0.0.10")

+5
source

Source: https://habr.com/ru/post/901904/


All Articles