Package oshi.hardware

Class NetworkIF

java.lang.Object
oshi.hardware.NetworkIF

@NotThreadSafe
public class NetworkIF
extends java.lang.Object
A network interface in the machine, including statistics

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 field bytesRecv.
    long getBytesSent()
    Getter for the field bytesSent.
    long getCollisions()
    Getter for the field collisions.
    java.lang.String getDisplayName()
    Interface description.
    int getIfType()
    (Windows, macOS) The NDIS Interface Type.
    long getInDrops()
    Getter for the field inDrops.
    long getInErrors()
    Getter for the field inErrors.
    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 field outErrors.
    long getPacketsRecv()
    Getter for the field packetsRecv.
    long getPacketsSent()
    Getter for the field packetsSent.
    java.lang.Short[] getPrefixLengths()
    The Internet Protocol (IP) v6 address.
    long getSpeed()
    Getter for the field speed.
    java.lang.Short[] getSubnetMasks()
    The Internet Protocol (IP) v4 subnet masks.
    long getTimeStamp()
    Getter for the field timeStamp.
    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 java NetworkInterface object.
    void setBytesRecv​(long bytesRecv)
    Setter for the field bytesRecv.
    void setBytesSent​(long bytesSent)
    Setter for the field bytesSent.
    void setCollisions​(long collisions)
    Setter for the field collisions.
    void setConnectorPresent​(boolean connectorPresent)
    Setter for the field connectorPresent.
    void setIfType​(int ifType)
    Setter for the field ifType.
    void setInDrops​(long inDrops)
    Setter for the field inDrops.
    void setInErrors​(long inErrors)
    Setter for the field inErrors.
    void setNdisPhysicalMediumType​(int ndisPhysicalMediumType)
    Setter for the field ndisPhysicalMediumType.
    void setNetworkInterface​(java.net.NetworkInterface networkInterface)
    Sets the network interface and calculates other information derived from it
    void setOutErrors​(long outErrors)
    Setter for the field outErrors.
    void setPacketsRecv​(long packetsRecv)
    Setter for the field packetsRecv.
    void setPacketsSent​(long packetsSent)
    Setter for the field packetsSent.
    void setSpeed​(long speed)
    Setter for the field speed.
    void setTimeStamp​(long timeStamp)
    Setter for the field timeStamp.
    java.lang.String toString()  
    boolean updateAttributes()
    Updates interface network statistics on this interface.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • queryNetworkInterface

      public java.net.NetworkInterface queryNetworkInterface()
      Gets the core java NetworkInterface 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 the setNetworkInterface(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 the setNetworkInterface(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 the setNetworkInterface(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 the setNetworkInterface(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 the setNetworkInterface(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 the setNetworkInterface(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 the Ntddndis.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 the updateAttributes() 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 the updateAttributes() 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 the updateAttributes() 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 the updateAttributes() 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 the updateAttributes() 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 the updateAttributes() 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 the updateAttributes() 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 the updateAttributes() 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 the updateAttributes() 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 class java.lang.Object