Linux下tcpdump命令的使用问题...

freshman_fantom_ywj 2011-12-09 04:21:13
最近要使用这个命令来控制抓包,有几个问题:

1. 如果想抓从一个IP段到另一个IP段(不是整个网络)的包 ,有什么简便的表达式没, 我现在知道的就只有:
tcpdump src \(<host1> or <host2> or <host3>... \) and dst \( <dhost1> or <dhost2> or <dhost3>... \)

2. 我想用-w <filename> 将包存到一个文件里, 但额外的是想有没有参数 可以控制这个保存文件的最大容量,当超过这个最大值是就停止执行tcpdump !

3. 尝试后台想用 execvp("tcpdump","-c 3000 -i eth0 host 192.168.1.1",NULL); 这个函数去启动tcpdump, 但是无意中发现 如果参数中 加上"> tcpdump.file" 这个重定向到文件的参数的话 ,execvp 会执行失败. 求解...

呵呵, 有点纠结 , 坐等回复!
...全文
330 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 forestdb 的回复:]

dst net net
True if the IPv4/v6 destination address of the packet has a net-
work number of net. Net may be either a name from the networks
database (/e……
[/Quote]
谢谢了, 不过这是匹配一个网段吧... 我想匹配随意给定的IP段, 例如 : 192.168.1.5 ~ 192.168.1.50 ... 一直没想出什么好办法 看Tcpdump文档都看了好几天了.
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 forestdb 的回复:]

前两个问题都可以通过man page解决。
man tcpdump可以发现[ -C file_size ],猜猜都能知道什么意思吧。
另外可以发现,src dst属于expression,而man pcap-filter有完整的列表,可以选取自己需要的。

至于execvp,这属于系统编程的范畴,简单的说,如果是编程来重定向,需要先
fd = open("tcpdump.file")
……
[/Quote]
受教了, 谢谢哈 !!!
ForestDB 2011-12-12
  • 打赏
  • 举报
回复
dst net net
True if the IPv4/v6 destination address of the packet has a net-
work number of net. Net may be either a name from the networks
database (/etc/networks, etc.) or a network number. An IPv4
network number can be written as a dotted quad (e.g.,
192.168.1.0), dotted triple (e.g., 192.168.1), dotted pair (e.g,
172.16), or single number (e.g., 10); the netmask is
255.255.255.255 for a dotted quad (which means that it¡¯s really
a host match), 255.255.255.0 for a dotted triple, 255.255.0.0
for a dotted pair, or 255.0.0.0 for a single number. An IPv6
network number must be written out fully; the netmask is
ff:ff:ff:ff:ff:ff:ff:ff, so IPv6 "network" matches are really
always host matches, and a network match requires a netmask
length.

src/dst 192.168.1

net net mask netmask
True if the IPv4 address matches net with the specific netmask.
May be qualified with src or dst. Note that this syntax is not
valid for IPv6 net.

net net/len
True if the IPv4/v6 address matches net with a netmask len bits
wide. May be qualified with src or dst.

net 192.168.1.0 mask 255.255.255.0
net 192.168.1.0/24
  • 打赏
  • 举报
回复
还是没有找到办法 解决怎么表示一个IP段的问题.... 纠结啊!
ForestDB 2011-12-09
  • 打赏
  • 举报
回复
前两个问题都可以通过man page解决。
man tcpdump可以发现[ -C file_size ],猜猜都能知道什么意思吧。
另外可以发现,src dst属于expression,而man pcap-filter有完整的列表,可以选取自己需要的。

至于execvp,这属于系统编程的范畴,简单的说,如果是编程来重定向,需要先
fd = open("tcpdump.file")
dup2(fd, STDOUT_FILENO)
完成重定向,然后再execvp。

很明显LZ想做package caputure相关的动作,推荐一个库libpcap。
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 qq120848369 的回复:]
net net mask mask
如果 IP 地址 匹配 指定 网络掩码(netmask) 的 net, 则 逻辑 为 真. 本原语 可以用 src 或 dst 修饰.
net net/len
如果 IP 地址 匹配 指定 网络掩码 的 net, ……
[/Quote]
用网络地址 加上 网络掩码 能确定某段IP么? 不能吧.
qq120848369 2011-12-09
  • 打赏
  • 举报
回复

net net mask mask
如果 IP 地址 匹配 指定 网络掩码(netmask) 的 net, 则 逻辑 为 真. 本原语 可以用 src 或 dst 修饰.
net net/len
如果 IP 地址 匹配 指定 网络掩码 的 net, 则 逻辑 为 真, 掩码 的 有效位宽 为 len. 本原语 可以用 src 或 dst 修饰.
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 qq120848369 的回复:]

exec是执行一个二进制程序, 重定向是shell的功能, 而你执行的不是shell而是tcpdump这个程序, 所以重定向没用.


[ -C file_size ] 好像是那么个作用,不过描述里更加复杂一些, 和-w配合不知道什么效果。

不会
[/Quote] 哦 原来执行失败是因为 这样, 开始愣没想明白! 谢谢了
qq120848369 2011-12-09
  • 打赏
  • 举报
回复
exec是执行一个二进制程序, 重定向是shell的功能, 而你执行的不是shell而是tcpdump这个程序, 所以重定向没用.


[ -C file_size ] 好像是那么个作用,不过描述里更加复杂一些, 和-w配合不知道什么效果。

不会

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧