NetworkInterface getByName Example

NetworkInterface class getByName example. This example shows you how to use getByName method.


NetworkInterface class getByName example. public static NetworkInterface getByName(String name) throws SocketException Searches for the network interface with the specified name.

Here is the code
/*
 * @ # GetByName.java
 * A class repersenting use to GetByName method 
 * of URL class in java.net package
 * version 23 June 2008
 * author Rose India 
 */

import java.net.*;
import java.util.*;

public class GetByName {

    public static void main(String args[]) throws Exception {
        NetworkInterface networkInterface =
                NetworkInterface.getByName("eth0");
        Enumeration e = networkInterface.getNetworkInterfaces();

        while (e.hasMoreElements()) {
            System.out.println(e.nextElement());
        }
    }
}

Output
name:eth0 (eth0) index: 2 addresses:
/fe80:0:0:0:219:d1ff:fe61:be38%2;
/192.168.10.222;

name:lo (lo) index: 1 addresses:
/0:0:0:0:0:0:0:1%1;
/127.0.0.1;

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US