- Forward


Working with Network Interfaces
in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Overview
Back SMYC Forward
  • Network Interface:
    • A connection between a computer and a (data communications) network
  • Hardware Network Interfaces:
    • A network interface card (NIC) provides one or more network interfaces
  • Software Network Interfaces:
    • Software can provide a network interface (e.g., the local loopback interface is implemented in software)
The java.net.NetworkInterface Class
Back SMYC Forward
  • Purpose:
    • An object that provides access to both hardware and software network interfaces
  • Constructing NetworkInterface Objects:
    • The static NetworkInterface.getNetworkInterfaces() method
    • The getSubinterface() and getParent() retrieve subinterfaces (a.k.a., virtual interfaces) and parent interfaces respectively
Displaying all Network Interfaces
Back SMYC Forward
javaexamples/internet/DisplayNIFs.java
 
Network Interface Addresses
Back SMYC Forward
  • Getting the IP Address:
    • getInetAddresses() returns an Enumeration of InetAddress objects
  • Getting the (Slightly More General) Interface Address:
    • getInterfaceAddresses() returns a List of InterfaceAddress objects
Displaying all Network Addresses
Back SMYC Forward
javaexamples/internet/DisplayAddresses.java
 
Obtaining Properties of Network Interfaces
Back SMYC Forward
  • Hardware-Related:
    • getHardwareAddress() returns the hardware (e.g., MAC for Ethernet) address
  • Other Properties:
    • getMTU() returns the maximum transmision unit
    • isLoopback()
    • isUp()
    • isVirtual()
    • supportsMulticast()
There's Always More to Learn
Back -