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 longgetBytesRecv()Getter for the fieldbytesRecv.longgetBytesSent()Getter for the fieldbytesSent.longgetCollisions()Getter for the fieldcollisions.java.lang.StringgetDisplayName()Interface description.intgetIfType()(Windows, macOS) The NDIS Interface Type.longgetInDrops()Getter for the fieldinDrops.longgetInErrors()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.StringgetMacaddr()The Media Access Control (MAC) address.intgetMTU()The interface Maximum Transmission Unit (MTU).java.lang.StringgetName()Interface name.intgetNdisPhysicalMediumType()(Windows Vista and higher only) The NDIS physical medium type.longgetOutErrors()Getter for the fieldoutErrors.longgetPacketsRecv()Getter for the fieldpacketsRecv.longgetPacketsSent()Getter for the fieldpacketsSent.java.lang.Short[]getPrefixLengths()The Internet Protocol (IP) v6 address.longgetSpeed()Getter for the fieldspeed.java.lang.Short[]getSubnetMasks()The Internet Protocol (IP) v4 subnet masks.longgetTimeStamp()Getter for the fieldtimeStamp.booleanisConnectorPresent()(Windows Vista and higher) Set if a connector is present on the network interface.booleanisKnownVmMacAddr()Determines if the MAC address on this interface corresponds to a known Virtual Machine.java.net.NetworkInterfacequeryNetworkInterface()Gets the core javaNetworkInterfaceobject.voidsetBytesRecv(long bytesRecv)Setter for the fieldbytesRecv.voidsetBytesSent(long bytesSent)Setter for the fieldbytesSent.voidsetCollisions(long collisions)Setter for the fieldcollisions.voidsetConnectorPresent(boolean connectorPresent)Setter for the fieldconnectorPresent.voidsetIfType(int ifType)Setter for the fieldifType.voidsetInDrops(long inDrops)Setter for the fieldinDrops.voidsetInErrors(long inErrors)Setter for the fieldinErrors.voidsetNdisPhysicalMediumType(int ndisPhysicalMediumType)Setter for the fieldndisPhysicalMediumType.voidsetNetworkInterface(java.net.NetworkInterface networkInterface)Sets the network interface and calculates other information derived from itvoidsetOutErrors(long outErrors)Setter for the fieldoutErrors.voidsetPacketsRecv(long packetsRecv)Setter for the fieldpacketsRecv.voidsetPacketsSent(long packetsSent)Setter for the fieldpacketsSent.voidsetSpeed(long speed)Setter for the fieldspeed.voidsetTimeStamp(long timeStamp)Setter for the fieldtimeStamp.java.lang.StringtoString()booleanupdateAttributes()Updates interface network statistics on this interface.
-
Constructor Details
-
NetworkIF
public NetworkIF()
-
-
Method Details
-
queryNetworkInterface
public java.net.NetworkInterface queryNetworkInterface()Gets the core javaNetworkInterfaceobject.- 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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_MEDIUMenumeration type defined in theNtddndis.hheader 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:
trueif 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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
NetworkIFis 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:
trueif the update was successful,falseotherwise.
-
isKnownVmMacAddr
public boolean isKnownVmMacAddr()Determines if the MAC address on this interface corresponds to a known Virtual Machine.- Returns:
trueif the MAC address corresponds to a known virtual machine.
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-