tcpdump交叉编译和一些简单命令

下面介绍一下具体过程。
1.在http://www.tcpdump.org下载libpcap-1.0.0.tar.gz和tcpdump-4.0.0.tar.gz两个文件。
2.将这两个文件放在/home下解压。
3.编译,安装libpcap-1.0.0:
   (1)进入libpcap目录,打开configure。将下面两端代码注释掉
       #if test -z "$with_pcap" && test "$cross_compiling" = yes; then
     # { { echo "$as_me:$LINENO: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&5
     #echo "$as_me: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&2;}
     #   { (exit 1); exit 1; }; }
     #fi
   .......
     #   if test $ac_cv_linux_vers = unknown ; then
     #   { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5
     #echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;}
     #   { (exit 1); exit 1; }; }
     #   fi

注释掉之后,再./configure --host=arm-linux CC=arm-linux-gcc, 会看到生成的Makefile.
(如果不注释掉上面两段代码,可能会出现determine linux version when cross-compiling或pcap type not determined when cross-compiling导致无法configure)。
  配置之后,会生成Makefile。打开Makefile发现CC=arm-uclibc-linux-gcc,说明交叉编译配置成功。然后make,make install。

3.编译,安装tcpdump-4.0.0
   (1)进入tcpdump目录,打开configure,将下面一段代码注释掉
     #   if test $ac_cv_linux_vers = unknown ; then
     #   { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5
     #echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;}
     #   { (exit 1); exit 1; }; }
     #   fi
注释掉之后,再./configure --host=arm-linux CC=arm-linux-gcc, 会看到生成的Makefile.

   (2)打开生成的Makefile,将INCLS项改为INCLS=-I.-I./../libpcap-1.0.0 -I$(srcdir)/missing -I/usr/local/include,
      然后make,make install。在/usr/local/sbin下有个tcpdump的二进制文件,这个就是交叉编译成功的tcpdump
   (3)将这个二进制文件放到tftpboot文件夹,用过tftp将这个文件下载到arm板上,chmod 777 tcpdump将其变为可执行文件。
   (4)运行tcpdump,成功!

tcp抓包的简单命令

tcpdump 的抓包保存到文件的命令参数是-w xxx.cap
抓eth1的包
tcpdump -i eth1 -w /tmp/xxx.cap
抓 192.168.1.123的包
tcpdump -i eth1 host 192.168.1.123 -w /tmp/xxx.cap
抓192.168.1.123的80端口的包
tcpdump -i eth1 host 192.168.1.123 and port 80 -w /tmp/xxx.cap
抓192.168.1.123的icmp的包
tcpdump -i eth1 host 192.168.1.123 and icmp -w /tmp/xxx.cap
抓192.168.1.123的80端口和110和25以外的其他端口的包
tcpdump -i eth1 host 192.168.1.123 and ! port 80 and ! port 25 and ! port 110 -w /tmp/xxx.cap
抓vlan 1的包
tcpdump -i eth1 port 80 and vlan 1 -w /tmp/xxx.cap
抓pppoe的密码
tcpdump -i eth1 pppoes -w /tmp/xxx.cap
以100m大小分割保存文件, 超过100m另开一个文件 -C 100m
抓10000个包后退出 -c 10000
后台抓包, 控制台退出也不会影响:
nohup tcpdump -i eth1 port 110 -w /tmp/xxx.cap &
抓下来的文件可以直接用ethereal 或者wireshark打开。

你可能感兴趣的:(抓包程序,工具)