3

Using java.net.NetworkInterface I am getting the status (up/down) of network.

I want to get the value of send and receive byte on the network card. And I need to calculate network utilization also.

How to get these in Java?

2 Answers2

2

I don't think there is a pure Java way of doing this. So one solution is to use JNI and a native library, which of course would have to be OS-specific.

If you want something more portable, I suggest trying out SNMP. All common OS should support querying such data via SNMP (perhaps after installing an SNMP server), and there are also Java SNMP client implementations available.

Philipp Wendler
  • 11,184
  • 7
  • 52
  • 87
  • SNMP is the correct answer. This is an example in python: [How can I check the data transfer on a network interface](http://stackoverflow.com/questions/7731411/how-can-i-check-the-data-transfer-on-a-network-interface-in-python/7791143#7791143) – Mike Pennington Dec 28 '11 at 12:54
1

I would suggest using OSHI. The NetworkIF class supports everything you need.

Cardinal System
  • 2,749
  • 3
  • 21
  • 42