style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-7505528228218001"
data-ad-slot="1225241371">

openOffline Method to access from Android Internal Storage

1 reply [Last post]
madhusudhanan91
Offline
Joined: 11/30/2015

Hi everyone,

I am using JnetPcap library to extract the packets from a Mobile Wireshark application required for Android project analysis. I have to capture the IP address from the pcap file and display the same on the Google Maps.

I am facing an issue reading the Internal Storage of the Android phone using the openOffline method... Can this method be used for Android Internal Storage File Directory ?? The same code is working if the directory path is specified in Windows OS running on a PC....

Any inputs would be highly appreciated...

Please find below the code for the same.

package appprofiler.appprofilerv1;

/**
* Created by soory_000 on 11/30/2015.
*/

import android.os.Environment;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jnetpcap.Pcap;
import org.jnetpcap.nio.JMemory;
import org.jnetpcap.packet.JFlow;
import org.jnetpcap.packet.JFlowKey;
import org.jnetpcap.packet.JFlowMap;
import org.jnetpcap.packet.JPacket;
import org.jnetpcap.packet.JPacketHandler;
import org.jnetpcap.packet.JScanner;
import org.jnetpcap.packet.PcapPacket;
import org.jnetpcap.protocol.network.Ip4;
import org.jnetpcap.protocol.tcpip.Http;
import org.jnetpcap.protocol.tcpip.Tcp;

public class IPExtract {
final static List ipaddress = new ArrayList();
private static String FILENAME;

public IPExtract(String Filename) {
this.FILENAME = Filename;
}

public static void main(String[] args) {
final StringBuilder errbuf = new StringBuilder();
final Pcap pcap = Pcap.openOffline(FILENAME, errbuf); // While trying to debug I am getting a Library error
if (pcap == null) {
System.err.println(errbuf);
return;
}
pcap.loop(Pcap.LOOP_INFINITE, new JPacketHandler() {

final Tcp tcp = new Tcp();

final Ip4 ip4 = new Ip4();
final Http http = new Http();
public void nextPacket(JPacket packet, StringBuilder errbuf) {

if (packet.hasHeader(Tcp.ID)) {
if (packet.hasHeader(tcp) && packet.hasHeader(http)) {

packet.getHeader(ip4);
byte[] sip = new byte[4];
sip = packet.getHeader(ip4).source();
byte[] dip = new byte[4];
dip = packet.getHeader(ip4).destination();
String destinationip = org.jnetpcap.packet.format.FormatUtils.ip(dip);
if (!(ipaddress.contains(destinationip))) {
ipaddress.add(destinationip);
}

}
}
}

}, errbuf);
ipaddresscollection();
// pcap.close();

}

public static List ipaddresscollection() {
return ipaddress;
}

}

DavidJones
Offline
Joined: 06/08/2015
I am looking through at this.

I am looking through at this. This can be a useful idea in the future. - Dennis Wong YOR Health

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.