Tuesday, March 24, 2009

Capture packets in Android - Tcpdump




I have wanted to do include this blogging activity as a part of my life and finally android takes the credit of pushing me over the edge,
My first post is going to be on using tcpdump in android.First i have a executable file of tcpdump which is precompiled for android,so if you are a lazy guy like me go and pull the image and start using it.

Tcpdump Usage

Tcp dump usage is pretty simple for those who are experts at it forgive me for posting such a meagre portion of its power.

there are various ways of using tcpdump and here is a set which just talks about using it based on source and destination port numbers.
To capture all traffic with host churchward as source or destination address
tcpdump host churchward

To capture all traffic with the tcp or udp, source or destination port number 53
tcpdump port 10008

To capture all traffic with the source address churchward
tcpdump src host churchward

To capture all trafffic with the destination tcp or udp port 10008
tcpdump dst port 10008

To capture all TCP traffic with the source address churchward
tcpdump tcp src host churchward

To capture all trafffic with the destination udp port 10008
tcpdump udp dst port 10008

The above instructions were cherry picked from here
Note: The above exe has been tested out on a development phone and also on the emulator, it has worked as expected in both the occasions.

Instructions to use capture packets

1.Download the executable from the above link push it into the emulator of the device using adb.
adb push tcpdump /data

2.
The below commands will move the binary into the emulator or the device.

adb shell
cd /data
chmod 777 tcpdump

3.Listen on the port and type of packets that you want to