Recently, I made an Android network packet capture tool. I searched the internet for a long time and found that I still had no clue. so I decided to work hard on the linux layer. so I used linux tcpdump to implement the packet capture function in simple words. define tcpdump, it is: dumpthetrafficonanetwork. it intercepts packets on the network according to the user's definition. it is the latest Android network packet capture tool.
I have searched the internet for a long time.
No clue found
So we need to work hard on the linux layer.
Therefore
TcpdumpTo implement the packet capture function.
To define tcpdump in a simple way, dump the traffic on anetwork is a packet analysis tool that intercepts packets on the network according to the user's definition.
As an essential tool for system administrators on the Internet, tcpdump, with its powerful functions and flexible interception policies, becomes one of the essential tools for every senior system administrator to analyze the network and troubleshoot problems.
Here I will mainly introduce how to use tcpdump on Android
I use a cracked version of G2 and a simulator.
Specifically, run linux commands in the APK program.
Tcpdump-p-vv-s 0-w/sdcard/capture. pcap
In this way, the captured package can be written into a capture. pcap file on the sdcard.
This file can be opened on the PC using wireshark for convenient viewing.
The specific source code is as follows:
MainHook. java
Package zy. hook;
Import java. io. IOException;
Import android. app. Activity;
Import android. OS. Bundle;
Import android. util. Log;
Public class MainHook extends Activity {
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Try {
// Runtime.getruntime(cmd.exe c ("su ");
// Runtime.getruntime(cmd.exe c ("dd if =/sdcard/tcpdump of =/data/local/tcpdump ");
// Runtime.getruntime(cmd.exe c ("chmod 6755/data/local/tcpdump ");
Runtime.getruntime(cmd.exe c ("tcpdump-p-vv-s 0-w/sdcard/capture. pcap ");
Log. I ("run", "success !!!!!!!!! ");
} Catch (IOException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
Log. I ("run", e. toString ());
}
}
}
AndroidManifest. xml
Package = "zy. hook"
Android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">
Android: label = "@ string/app_name">
In particular, do not forget the permissions
Statement
Run the program and we can capture packets.
The capture. pcap file is generated on the sdcard.
After capturing the file for a period of time, export the file from the sdcard
Then we use wireshark to open
You can conveniently view the packages we caught.
Hope to be useful to everyone
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service