前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Scapy Sniffer的filter语法「建议收藏」

Scapy Sniffer的filter语法「建议收藏」

作者头像
Java架构师必看
发布2022-08-15 17:05:48
1.4K0
发布2022-08-15 17:05:48
举报
文章被收录于专栏:Java架构师必看Java架构师必看

大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说Scapy Sniffer的filter语法「建议收藏」,希望能够帮助大家进步!!!

qualifier:

  1. type(定义了类型)

可选值:host, net, port, portrange

例如:

host hostnameA

net 172.31 //相当于172.31.0.0/16,又例如:192.168.1相当于192.168.1.0/24

port 80

portrange 6000-6010

  1. dir(direction,定义了传输方向)

可选值:src, dst, src or dst, src and dst

例如:

src net 172.31

src or dst port 21

  1. proto(protocol定义了网络协议)

可选值:ether, fddi, tr, wlan, ip, ip6, arp, rarp, decnet, tcp, udp, icmp

(fddi, tr, wlan是ether的别名, 包结构很类似)

例如:

ether src hostnameA

arp net 172.31

udp portrange 7000-8000

连接词:and, or, not

例如:

tcp or udp

not icmp

常用的一些表达式([]表示可选项,/表示并列可选项):

src/dst host host

IPv4/v6的源/目的主机为host,既可以是IP地址又可以是hostname,前面可以追加ip,arp, rarp或ip6,例如:

ip host host

ether host/src/dstehost

以太网地址/源地址/目的地址为ehost,ehost可以是名称或number

gateway host

报文以host作为gateway

src/dst net net

IPv4/v6源/目的地址的网络号为net,net既可以是一个网络名也可以是一个网络号,IPv4的网络号可以写成点分式,例如:192.168.1.0,或者192.168.1(等价于192.168.1.0/24),或者172.16(等价于172.16.0.0/16),或者10(等价于10.0.0.0/8)。IPv6的掩码为ff:ff:ff:ff:ff:ff,所以IPv6的地址匹配模式为全匹配,需要完全匹配对应的主机IPv6地址

net net mask netmask

匹配网络号和掩码,掩码格式例如:255.255.0.0,IPv6不支持此语法

net net/len

netmask的另一种写法,len指定子网掩码的长度

src/dst port port

匹配源/目的端口号

src/dst portrangeport1-port2

匹配源/目的端口范围

less length

报文长度小于等于length,等价于len <= length

greater length

报文长度大于等于length,等价于len>= length

ip proto protocol

匹配IPv4,协议类型为protocol,protocol可取值为:icmp, icmp6, igmp, igrp, pim, ah,esp, vrrp, udp, tcp,注意icmp, tcp, udp也是关键字,所以需要使用“\”进行转义

ip6 proto protocol

匹配IPv6的协议

ip/ip6 protochain protocol

匹配IPv4/v6协议,协议中的protocolheader chain中包含protocol,例如:

ip6 protochain 6

(注:6代表TCP)

Value (in decimal)

Header

0

Hop-by-Hop Options Header

6

TCP

17

UDP

41

Encapsulated IPv6 Header

43

Routing Header

44

Fragment Header

46

Resource ReSerVation Protocol

50

Encapsulating Security Payload

51

Authentication Header

58

ICMPv6

59

No next header

60

Destination Options Header

ether broadcast

匹配以太网广播报文

ip broadcast

匹配IPv4广播报文

参考链接:

http://biot.com/capstats/bpf.html

http://alumni.cs.ucr.edu/~marios/ethereal-tcpdump.pdf

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-08-142,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档