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, wlanether的别名, 包结构很类似)

例如:

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, rarpip6,例如:

ip host host

 

ether host/src/dstehost

以太网地址/源地址/目的地址ehostehost可以是名称或number

 

gateway host

报文以host作为gateway

 

[src/dst] net net

IPv4/v6[/目的]地址的网络号为netnet既可以是一个网络名也可以是一个网络号,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.0IPv6不支持此语法

 

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

  • 102
    点赞
  • 94
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值