Reputation: 663
I have been trying to capture the packets in my android app when connected to Wifi.
I am using a broadcast receiver class.
I have successfully received the broadcast when connected to a wifi network, using this code:
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (null != activeNetwork) {
if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI){
//wificonnected
return 1;
}
}
I want to capture the packets when network connected. I know everything about wifiInfo and WifiManager class.
I am trying here with jNetPcap library. How to capture those packets? I have no ideas.
Please help me guys...
Upvotes: 0
Views: 1829
Reputation: 2255
You'll need to use VpnService to redirect all of your device's network traffic through your app.
If you want to use jNetPcap, here's a working example (more info here and here).
After reading your traffic, you'll have to open one socket to each destination port/ip as stated here. It won't be easy, though. You'll have to understand VpnService first, I suggest you take a look at ToyVpn as a start.
Hope this info helps.
Upvotes: 2