Reputation: 11
I want to make an android apps to capture the network traffic without root like PCAPdroid, but simple one.
I just need capture TCP traffic and get its' TX Payload from that captured TCP Connection like PCAPdroid
PCAPdroid could capture TX Payload like this:
I have successfully retrieved destination IP, destination PORT, source IP and source PORT but not the TX Payload.
Here is my function to retrieve destination IP, destination PORT, source IP and source PORT.
How about to retrieve it's TX Payload like PCAPdroid?
Thankyou.
private void logPacket(ByteBuffer packet) {
// Extract more detailed packet information for logging
byte[] srcIpBytes = new byte[4];
packet.position(12);
packet.get(srcIpBytes);
String srcIp = String.format("%d.%d.%d.%d", srcIpBytes[0] & 0xFF, srcIpBytes[1] & 0xFF, srcIpBytes[2] & 0xFF, srcIpBytes[3] & 0xFF);
byte[] destIpBytes = new byte[4];
packet.position(16);
packet.get(destIpBytes);
String destIp = String.format("%d.%d.%d.%d", destIpBytes[0] & 0xFF, destIpBytes[1] & 0xFF, destIpBytes[2] & 0xFF, destIpBytes[3] & 0xFF);
int srcPort = packet.getShort(20) & 0xFFFF;
int destPort = packet.getShort(22) & 0xFFFF;
System.out.println("Intercepted packet:");
System.out.println("Source IP: " + srcIp);
System.out.println("Destination IP: " + destIp);
System.out.println("Source Port: " + srcPort);
System.out.println("Destination Port: " + destPort);
//start payload here
//end payload here
}
Upvotes: 0
Views: 45