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

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

内容简介:[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


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

查看所有标签

猜你喜欢:

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

Masterminds of Programming

Masterminds of Programming

Federico Biancuzzi、Chromatic / O'Reilly Media / 2009-03-27 / USD 39.99

Description Masterminds of Programming features exclusive interviews with the creators of several historic and highly influential programming languages. Think along with Adin D. Falkoff (APL), Jame......一起来看看 《Masterminds of Programming》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

html转js在线工具
html转js在线工具

html转js在线工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具