Other

Bandwith on a capture

I have made a capture program which captures packet from the wire and it works as it should be. Now I've tried to calculate the bandwith of the incomming packets, but I'm not sure if I am doing it correctly. in the dumphandler I made a variable to count the number of bytes captured. This is down with the folowing line of code: bcount = bcount + header.caplen(); (is this the right way to do it?) next to that I'm getting a timestamp before and after the loop starts and do some calculation on the bandwith:
 
        int x = Integer.parseInt(numberofPackets.getText());    
        long start = System.currentTimeMillis();
        bcount = 0;
        pcap.loop(x,dumpHandler, dumper); // Special native dumper call to loop 
        long end = System.currentTimeMillis();
       
       
        double bps =  (bcount /((end - start) / 1000))*8 ;
        double Kbps = (bps/1024);
        double Mbps = Kbps/1024;
        System.out.printf("Bps= %f\n",bps);
        System.out.printf("Kbps= %f\n",Kbps);
        System.out.printf("Mbps= %f\n",Mbps);
As far as my calculation goes. But here is the thing i was wondering. in a test example where I captre 10k packets it shows me a rate of 4,7Mbps but when i open the pcap file in wireshark and look at their stats they say that my rate is 4,2Mbits. the only thing I can understand is that with my calculation there is some overhead in timestamping in the pcap.loop function, but that doesn't explain why my calculated rate is HIGHER than the rate calculated by wireshark. how do I explain the >10% difference in these 2 rates? anyone anny idea on how wireshark calculates it. Or am I doing someting completely stupid in my calculation? thanks in advance, s0ulmaster

Compile error with exmaple code

I try compiling classic exmaple and packet sender. I end up getting the same error with both of them. The error that I get from compiler is "Exception in thread "main" java.lang.Error: Unresolved compilation problem".

offline capturing not working on netbeans

hi
i have gone through the offline example
http://jnetpcap.com/tutorial/usage

it is successfully running on eclipse but not working on netbeans IDE i am developing a packet analyzer tool in netbeans..
please help me on this

Thanx,

Filtering PcapDumper

I was hoping to use jnetpcap to read in an already saved pcap file, filter and potentially edit the packets within before resaving into a pcap file, using the dumpHandler example seems to be my best bet but I'm not sure how to extract a JPacket from the JBuffer or if this is even possible. Note I'm very new to jnetpcap.

edit. I've solved filtering the packets however editing the headers seems like a daunting task, any help would be greatly appreciated

Can not capture packets from iPhone devices

Hi all. This is my first time on this forum, so please be gentle Smile. I've modified the classic example of JnetPcap and I am trying to extract the IP and MAC address from every packet that I receive. With this, I'll be able to see how many devices are there connected to the same wireless network as mine and also get their MACs and IPs on the way (I don't want to ping all the addresses since its time taking). The code below works fine, and I also see all the devices connected to the WiFi except for iPhones and I can't figure out why. I already know what IP of the iPhone device is, so I ping the IP. After the ping, I start receiving packets from iPhone along with its IP and MAC. But if i don't ping the IP, I don't receive any packets from it. Any help would be appreciated.


package com.prototype;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import org.jnetpcap.Pcap;
import org.jnetpcap.PcapIf;
import org.jnetpcap.packet.PcapPacket;
import org.jnetpcap.packet.PcapPacketHandler;
import org.jnetpcap.packet.format.FormatUtils;
import org.jnetpcap.protocol.lan.Ethernet;
import org.jnetpcap.protocol.network.Ip4;

public class GetIPnMac {

private static ArrayList ips = new ArrayList();
private static ArrayList macs = new ArrayList();

public static void main(String[] args) throws UnknownHostException,
IOException {

List alldevs = new ArrayList(); // Will be filled with
// NICs
StringBuilder errbuf = new StringBuilder(); // For any error msgs

/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
int r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {

Syndicate content