[TCP/IP] 构造并发送ICMP echo包

栏目: 服务器 · 发布时间: 6年前

内容简介:[TCP/IP] 构造并发送ICMP echo包

安装 dpkt

dpkt is a python module for fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols.

pip install dpkt

构造Echo packet

import socket

import dpkt


echo = dpkt.icmp.ICMP.Echo()
echo.id = 10086
echo.seq = 1
echo.data = 'hello world'

icmp = dpkt.icmp.ICMP()
icmp.type = dpkt.icmp.ICMP_ECHO
icmp.data = echo

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, dpkt.ip.IP_PROTO_ICMP)
s.connect(('10.10.10.10', 1))
sent = s.send(str(icmp))

print('sent %d bytes' % sent)

监听echo包

# sudo tcpdump -i eth0 icmp and icmp[icmptype]=icmp-echo
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes

08:26:32.397922 IP 10.10.10.9 > 10.10.10.10: ICMP echo request, id 10086, seq 1, length 19

参考

  1. dpkt Tutorial #1: ICMP Echo
Bits 160-167 168-175 176-183 184-191
160 Type Code 校验码(checksum)
192 ID 序号(sequence)

0


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Spark

Spark

Bill Chambers、Matei Zaharia / O′Reilly / 2017-10-31 / GBP 39.99

Learn how to use, deploy, and maintain Apache Spark with this comprehensive guide, written by the creators of the open-source cluster-computing framework. With an emphasis on improvements and new feat......一起来看看 《Spark》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码