views:

164

answers:

3

I want to know the exact amount of data which is getting transferred through a particular network interface for logging purpose, is there any standard library or api call from which I can do this in a cross platfrom way?

+2  A: 

This seems to do what you'd like. At least, I think it will point you in the right direction: http://jnetpcap.com/

edit: While not strictly cross-platform, libpcap has libraries for all major platforms so I wouldn't consider that a show-stopper, but I'm not the one that needs it.

MattC
Note that this library relies on native code accessed via JNI. There is no cross-platform way to do what you're trying to do. Java might not be the best fit.
Rob H
A: 

SNMP4J will let you read the interface mib of any SNMP-compliant device. Linux and OSX (probably) have an SNMP daemon already running; Windows has an SNMP service that you can install though Programs and Features in Control Panel.

Andrew Duffy
A: 

jNetPcap uses Sigar in some of its unit tests. Sigar advertizes itself as a "portable interface for gathering system information" including network interface detection, configuration info and metrics. Take a look at its NetInterfaceStat class.

Note that Sigar also relies on platform specific JNIs, i.e. Rob H's remark still applies.

bromfiets