Skip to content

anonymous /2

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
run:
Display name: em1
Name: em1
InetAddress: /192.168.1.103
Display name: lo
Name: lo
InetAddress: /127.0.0.1
BUILD SUCCESSFUL (total time: 0 seconds)
package test;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
public class Test11 {
public static void main(String args[]) throws SocketException {
Enumeration nets = NetworkInterface.getNetworkInterfaces();
for (Iterator it = Collections.list(nets).iterator(); it.hasNext();) {
NetworkInterface netint = (NetworkInterface) it.next();
displayInterfaceInformation(netint);
}
}
static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
System.out.printf("Display name: %s\n", netint.getDisplayName());
System.out.printf("Name: %s\n", netint.getName());
Enumeration inetAddresses = netint.getInetAddresses();
for (Iterator it = Collections.list(inetAddresses).iterator(); it.hasNext();) {
InetAddress inetAddress = (InetAddress) it.next();
System.out.printf("InetAddress: %s\n", inetAddress);
}
System.out.printf("\n");
}
}
@dgrant

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.