Package oshi.hardware

Class NetworkIF

java.lang.Object
oshi.hardware.NetworkIF

public class NetworkIF
extends java.lang.Object
A network interface in the machine, including statistics
  • 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.
    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.
    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.
    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 setInDrops​(long inDrops)
    Setter for the field inDrops.
    void setInErrors​(long inErrors)
    Setter for the field inErrors.
    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

    • 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.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object