前阵子,使用第三方开源jar包sigar.jar,获取网络传输信息,发现数据很大?
Sigar sigar = new Sigar();
String ifNames[] = sigar.getNetInterfaceList();
String name = ifNames[0];
NetInterfaceConfig ifconfig = sigar.getNetInterfaceConfig(name);
System.out.println("网络设备名: " + name);// 网络设备名
System.out.println("IP地址: " + ifconfig.getAddress());// IP地址
System.out.println("子网掩码: " + ifconfig.getNetmask());// 子网掩码
NetInterfaceStat ifstat = sigar.getNetInterfaceStat(name);
System.out.println(name + "接收到的总字节数:" + ifstat.getRxBytes() * 8);// 接收到的总字节数
System.out.println(name + "发送的总字节数:" + ifstat.getTxBytes() * 8);// 发送的总字节数
网络设备名: eth0
IP地址: 192.168.0.101
子网掩码: 255.255.255.0
eth0接收到的总字节数:5988097416
eth0发送的总字节数:5957383712
但是我监控的主机