Class NetworkIF
@NotThreadSafe public class NetworkIF extends java.lang.Object
Thread safe if both threads only use getters, or if setter usage is externally synchronized.
-
Constructor Summary
Constructors Constructor Description NetworkIF()
-
Method Summary
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.int
getIfType()
(Windows, macOS) The NDIS Interface Type.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.int
getMTU()
The interface Maximum Transmission Unit (MTU).java.lang.String
getName()
Interface name.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
.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 the core javaNetworkInterface
object.void
setBytesRecv(long bytesRecv)
Setter for the fieldbytesRecv
.void
setBytesSent(long bytesSent)
Setter for the fieldbytesSent
.void
setCollisions(long collisions)
Setter for the fieldcollisions
.void
setConnectorPresent(boolean connectorPresent)
Setter for the fieldconnectorPresent
.void
setIfType(int ifType)
Setter for the fieldifType
.void
setInDrops(long inDrops)
Setter for the fieldinDrops
.void
setInErrors(long inErrors)
Setter for the fieldinErrors
.void
setNdisPhysicalMediumType(int ndisPhysicalMediumType)
Setter for the fieldndisPhysicalMediumType
.void
setNetworkInterface(java.net.NetworkInterface networkInterface)
Sets the network interface and calculates other information derived from itvoid
setOutErrors(long outErrors)
Setter for the fieldoutErrors
.void
setPacketsRecv(long packetsRecv)
Setter for the fieldpacketsRecv
.void
setPacketsSent(long packetsSent)
Setter for the fieldpacketsSent
.void
setSpeed(long speed)
Setter for the fieldspeed
.void
setTimeStamp(long timeStamp)
Setter for the fieldtimeStamp
.java.lang.String
toString()
boolean
updateAttributes()
Updates interface network statistics on this interface.
-
Constructor Details
-
NetworkIF
public NetworkIF()
-
-
Method Details
-
queryNetworkInterface
public java.net.NetworkInterface queryNetworkInterface()Gets the core javaNetworkInterface
object.- Returns:
- the network interface, an instance of
NetworkInterface
.
-
setNetworkInterface
public void setNetworkInterface(java.net.NetworkInterface networkInterface)Sets the network interface and calculates other information derived from it- Parameters:
networkInterface
- The network interface to set
-
getName
public java.lang.String getName()Interface name.
- Returns:
- The interface name.
-
getDisplayName
public java.lang.String getDisplayName()Interface description.
- Returns:
- The description of the network interface. On some platforms, this is identical to the name.
-
getMTU
public int getMTU()The interface Maximum Transmission Unit (MTU).
- Returns:
- The MTU of the network interface.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute thesetNetworkInterface(NetworkInterface)
method
-
getMacaddr
public 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. To update this value, execute thesetNetworkInterface(NetworkInterface)
method
-
getIPv4addr
public java.lang.String[] getIPv4addr()The Internet Protocol (IP) v4 address.
- Returns:
- The IPv4 Addresses.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute thesetNetworkInterface(NetworkInterface)
method
-
getSubnetMasks
public java.lang.Short[] getSubnetMasks()The Internet Protocol (IP) v4 subnet masks.
- Returns:
- The IPv4 subnet mask length. Ranges between 0-32.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute thesetNetworkInterface(NetworkInterface)
method.
-
getIPv6addr
public java.lang.String[] getIPv6addr()The Internet Protocol (IP) v6 address.
- Returns:
- The IPv6 Addresses.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute thesetNetworkInterface(NetworkInterface)
method
-
getPrefixLengths
public java.lang.Short[] getPrefixLengths()The Internet Protocol (IP) v6 address.
- Returns:
- The IPv6 address prefix lengths. Ranges between 0-128.
This value is set when the
NetworkIF
is instantiated and may not be up to date. To update this value, execute thesetNetworkInterface(NetworkInterface)
method
-
getIfType
public 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
-
setIfType
public void setIfType(int ifType)Setter for the field
ifType
.- Parameters:
ifType
- the ifType to set
-
getNdisPhysicalMediumType
public int getNdisPhysicalMediumType()(Windows Vista and higher only) The NDIS physical medium type. This member can be one of the values from the
NDIS_PHYSICAL_MEDIUM
enumeration type defined in theNtddndis.h
header file.- Returns:
- the ndisPhysicalMediumType
-
setNdisPhysicalMediumType
public void setNdisPhysicalMediumType(int ndisPhysicalMediumType)Setter for the field
ndisPhysicalMediumType
.- Parameters:
ndisPhysicalMediumType
- the ndisPhysicalMediumType to set
-
isConnectorPresent
public 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
-
setConnectorPresent
public void setConnectorPresent(boolean connectorPresent)Setter for the field
connectorPresent
.- Parameters:
connectorPresent
- the connectorPresent to set
-
getBytesRecv
public 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
-
setBytesRecv
public void setBytesRecv(long bytesRecv)Setter for the field
bytesRecv
.- Parameters:
bytesRecv
- Set Bytes Received
-
getBytesSent
public 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
-
setBytesSent
public void setBytesSent(long bytesSent)Setter for the field
bytesSent
.- Parameters:
bytesSent
- Set the Bytes Sent
-
getPacketsRecv
public 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
-
setPacketsRecv
public void setPacketsRecv(long packetsRecv)Setter for the field
packetsRecv
.- Parameters:
packetsRecv
- Set The Packets Received
-
getPacketsSent
public 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
-
setPacketsSent
public void setPacketsSent(long packetsSent)Setter for the field
packetsSent
.- Parameters:
packetsSent
- Set The Packets Sent
-
getInErrors
public 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
-
setInErrors
public void setInErrors(long inErrors)Setter for the field
inErrors
.- Parameters:
inErrors
- The Input Errors to set.
-
getOutErrors
public 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
-
setOutErrors
public void setOutErrors(long outErrors)Setter for the field
outErrors
.- Parameters:
outErrors
- The Output Errors to set.
-
getInDrops
public 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
-
setInDrops
public void setInDrops(long inDrops)Setter for the field
inDrops
.- Parameters:
inDrops
- The incoming (receive) dropped packets to set.
-
getCollisions
public 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
-
setCollisions
public void setCollisions(long collisions)Setter for the field
collisions
.- Parameters:
collisions
- The collisions to set.
-
getSpeed
public 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
-
setSpeed
public void setSpeed(long speed)Setter for the field
speed
.- Parameters:
speed
- Set the speed of the network interface
-
getTimeStamp
public long getTimeStamp()Getter for the field
timeStamp
.- Returns:
- Returns the timeStamp.
-
setTimeStamp
public void setTimeStamp(long timeStamp)Setter for the field
timeStamp
.- Parameters:
timeStamp
- The timeStamp to set.
-
updateAttributes
public 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.
-
isKnownVmMacAddr
public 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.
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-