如何在Python中生成Tcp,ip和Udp数据包? [英] How To Generate Tcp,ip And Udp Packets In Python?
本文介绍了如何在Python中生成Tcp,ip和Udp数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我生成UDP,TCP和IP数据包的基本步骤是什么.以及如何使用Python生成它?
Can anyone tell me what is the basic step to generate UDP, TCP and IP Packets. And how can i generate it using Python?
推荐答案
根据jokeysmurf的建议,您可以制作带有鱼尾的数据包
as suggested by jokeysmurf you might craft packets with scapy
如果您要发送/接收普通数据包,则应使用套接字或套接字服务器
if you you want to send/receive usual packets then you should use socket or socketserver
- http://docs.python.org/library/socket.html#module-socket
- http://docs.python.org/library/socketserver.html#module-SocketServer
- http://docs.python.org/library/socket.html#module-socket
- http://docs.python.org/library/socketserver.html#module-SocketServer
使用以下命令将TCP发送到Google的端口80
to send TCP to google's port 80 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)
使其变为udp,将SOCK_STREAM更改为SOCK_DGRAM
to make it udp change SOCK_STREAM to SOCK_DGRAM
这篇关于如何在Python中生成Tcp,ip和Udp数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文