Interface NetworkIF
-
- All Known Implementing Classes:
AbstractNetworkIF
,AixNetworkIF
,BsdNetworkIF
,LinuxNetworkIF
,MacNetworkIF
,SolarisNetworkIF
,WindowsNetworkIF
@ThreadSafe public interface NetworkIF
A network interface in the machine, including statistics.Thread safe for the designed use of retrieving the most recent data. Users should be aware that the
updateAttributes()
method may update attributes, including the time stamp, and should externally synchronize such usage to ensure consistent calculations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
NetworkIF.IfOperStatus
The current operational state of a network interface.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description long
getBytesRecv()
Getter for the fieldbytesRecv
.long
getBytesSent()
Getter for the fieldbytesSent
.long
getCollisions()
Getter for the fieldcollisions
.java.lang.String
getDisplayName()
Interface description.default java.lang.String
getIfAlias()
TheifAlias
as described in RFC 2863.default NetworkIF.IfOperStatus
getIfOperStatus()
TheifOperStatus
as described in RFC 2863.default int
getIfType()
(Windows, macOS) The NDIS Interface Type.int
getIndex()
Interface index.long
getInDrops()
Getter for the fieldinDrops
.long
getInErrors()
Getter for the fieldinErrors
.java.lang.String[]
getIPv4addr()
The Internet Protocol (IP) v4 address.java.lang.String[]
getIPv6addr()
The Internet Protocol (IP) v6 address.java.lang.String
getMacaddr()
The Media Access Control (MAC) address.long
getMTU()
The interface Maximum Transmission Unit (MTU).java.lang.String
getName()
Interface name.default int
getNdisPhysicalMediumType()
(Windows Vista and higher only) The NDIS physical medium type.long
getOutErrors()
Getter for the fieldoutErrors
.long
getPacketsRecv()
Getter for the fieldpacketsRecv
.long
getPacketsSent()
Getter for the fieldpacketsSent
.java.lang.Short[]
getPrefixLengths()
The Internet Protocol (IP) v6 address.long
getSpeed()
Getter for the fieldspeed
.java.lang.Short[]
getSubnetMasks()
The Internet Protocol (IP) v4 subnet masks.long
getTimeStamp()
Getter for the fieldtimeStamp
.default boolean
isConnectorPresent()
(Windows Vista and higher) Set if a connector is present on the network interface.boolean
isKnownVmMacAddr()
Determines if the MAC address on this interface corresponds to a known Virtual Machine.java.net.NetworkInterface
queryNetworkInterface()
Gets theNetworkInterface
object.boolean
updateAttributes()
Updates interface network statistics on this interface.
-
-
-
Method Detail
-
queryNetworkInterface
java.net.NetworkInterface queryNetworkInterface()
Gets theNetworkInterface
object.- Returns:
- the network interface, an instance of
NetworkInterface
.
-
getName
java.lang.String getName()
Interface name.- Returns:
- The interface name.
-
getIndex
int getIndex()
Interface index.- Returns:
- The index of the network interface.
-
getDisplayName
java.lang.String getDisplayName()
Interface description.- Returns:
- The description of the network interface. On some platforms, this is identical to the name.
-
getIfAlias
default java.lang.String getIfAlias()
TheifAlias
as described in RFC 2863.The ifAlias object allows a network manager to give one or more interfaces their own unique names, irrespective of any interface-stack relationship. Further, the ifAlias name is non-volatile, and thus an interface must retain its assigned ifAlias value across reboots, even if an agent chooses a new ifIndex value for the interface.
Only implemented for Windows (Vista and newer) and Linux.
- Returns:
- The
ifAlias
of the interface if available, otherwise the empty string.
-
getIfOperStatus
default NetworkIF.IfOperStatus getIfOperStatus()
TheifOperStatus
as described in RFC 2863.Only implemented for Windows (Vista and newer) and Linux.
- Returns:
- The current operational state of the interface.
-
getMTU
long getMTU()
The interface Maximum Transmission Unit (MTU).- Returns:
- The MTU of the network interface.
The value is a 32-bit integer which may be unsigned on some operating systems. On Windows, some non-physical interfaces (e.g., loopback) may return a value of -1 which is equivalent to the maximum unsigned integer value.
This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getMacaddr
java.lang.String getMacaddr()
The Media Access Control (MAC) address.- Returns:
- The MAC Address.
This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getIPv4addr
java.lang.String[] getIPv4addr()
The Internet Protocol (IP) v4 address.- Returns:
- An array of IPv4 Addresses.
This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getSubnetMasks
java.lang.Short[] getSubnetMasks()
The Internet Protocol (IP) v4 subnet masks.- Returns:
- An array of IPv4 subnet mask lengths, corresponding to the IPv4 addresses from
getIPv4addr()
. Ranges between 0-32.This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getIPv6addr
java.lang.String[] getIPv6addr()
The Internet Protocol (IP) v6 address.- Returns:
- An array of IPv6 Addresses.
This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getPrefixLengths
java.lang.Short[] getPrefixLengths()
The Internet Protocol (IP) v6 address.- Returns:
- The IPv6 address prefix lengths, corresponding to the IPv6 addresses from
getIPv6addr()
. Ranges between 0-128.This value is set when the
NetworkIF
is instantiated and may not be up to date.
-
getIfType
default int getIfType()
(Windows, macOS) The NDIS Interface Type. NDIS interface types are registered with the Internet Assigned Numbers Authority (IANA), which publishes a list of interface types periodically in the Assigned Numbers RFC, or in a derivative of it that is specific to Internet network management number assignments.(Linux) ARP Protocol hardware identifiers defined in
include/uapi/linux/if_arp.h
- Returns:
- the ifType
-
getNdisPhysicalMediumType
default int getNdisPhysicalMediumType()
(Windows Vista and higher only) The NDIS physical medium type. This member can be one of the values from theNDIS_PHYSICAL_MEDIUM
enumeration type defined in theNtddndis.h
header file.- Returns:
- the ndisPhysicalMediumType
-
isConnectorPresent
default boolean isConnectorPresent()
(Windows Vista and higher) Set if a connector is present on the network interface.(Linux) Indicates the current physical link state of the interface.
- Returns:
true
if there is a physical network adapter (Windows) or a connected cable (Linux), false otherwise
-
getBytesRecv
long getBytesRecv()
Getter for the field
bytesRecv
.- Returns:
- The Bytes Received.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute theupdateAttributes()
method
-
getBytesSent
long getBytesSent()
Getter for the field
bytesSent
.- Returns:
- The Bytes Sent.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute theupdateAttributes()
method
-
getPacketsRecv
long getPacketsRecv()
Getter for the field
packetsRecv
.- Returns:
- The Packets Received.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute theupdateAttributes()
method
-
getPacketsSent
long getPacketsSent()
Getter for the field
packetsSent
.- Returns:
- The Packets Sent.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute theupdateAttributes()
method
-
getInErrors
long getInErrors()
Getter for the field
inErrors
.- Returns:
- Input Errors.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute theupdateAttributes()
method
-
getOutErrors
long getOutErrors()
Getter for the field
outErrors
.- Returns:
- The Output Errors.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute theupdateAttributes()
method
-
getInDrops
long getInDrops()
Getter for the field
inDrops
.- Returns:
- Incoming/Received dropped packets. On Windows, returns discarded incoming packets.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute theupdateAttributes()
method
-
getCollisions
long getCollisions()
Getter for the field
collisions
.- Returns:
- Packet collisions. On Windows, returns discarded outgoing packets.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute theupdateAttributes()
method
-
getSpeed
long getSpeed()
Getter for the field
speed
.- Returns:
- The speed of the network interface in bits per second.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute theupdateAttributes()
method
-
getTimeStamp
long getTimeStamp()
Getter for the field
timeStamp
.- Returns:
- Returns the timeStamp.
-
isKnownVmMacAddr
boolean isKnownVmMacAddr()
Determines if the MAC address on this interface corresponds to a known Virtual Machine.- Returns:
true
if the MAC address corresponds to a known virtual machine.
-
updateAttributes
boolean updateAttributes()
Updates interface network statistics on this interface. Statistics include packets and bytes sent and received, and interface speed.- Returns:
true
if the update was successful,false
otherwise.
-
-