Get network interface from an IP address in Java

Description

The following code shows how to get network interface from an IP address.

Example


//from  w w w .j  ava2 s .com
import java.net.InetAddress;
import java.net.NetworkInterface;

public class Main {
  public static void main(String[] args) throws Exception {
    InetAddress address = InetAddress.getLocalHost();

    NetworkInterface ni = NetworkInterface.getByInetAddress(address);
    System.out.println(ni.getName());

    
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode