Android中利用tcp dump抓包

来源:互联网 发布:excel关联表格数据 编辑:程序博客网 时间:2024/06/05 17:57

tcpdump for Android(抓TCP数据包工具)

  如果要抓TCP数据包,可以使用TCPdump工具,类似于windows/linux下使用的这个工具一样。

具体方法是下载tcpdump 还有个地址是http://www.strazzere.com/android/tcpdump ,详细使用请参考http://www.tcpdump.org/里面的文档

你需要root权限,

adb root

adb remount

adb push  c:\wherever_you_put\tcpdump /data/local/tcpdump
adb shell chmod 6755  /data/local/
tcpdump

抓包很简单

adb shell tcpdump -w /data/capture0.pcap

adb shell tcpdump ip 10.1.2.13 and 10.2.3.12 -w /data/capture1.pcap

或者
adb shell
tcpdump -p-vv -s 0 -w /sdcard/capture.pcap
# "-p": disable promiscuous mode (doesn't work anyway)
# "-s 0": capture the entire packet
# "-w": write packets to a file (rather than printing to stdout)
  
... do whatever you want to capture,then ^C to stop it ...
导出

adb pull /data/capture0.pcap   /home/linghu/

adb pull  /sdcard/capture.pcap  /home/linghu/


下载wireshark查看数据包,地址是http://www.wireshark.org/download.html,打开这个数据包,就可以查看数据包内容了。

参考文档:http://prem-android.blogspot.com/2009/03/capture-packets-in-android-tcpdump.html