Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

/2

Created September 18, 2011 18:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1225358 to your computer and use it in GitHub Desktop.
Save anonymous/1225358 to your computer and use it in GitHub Desktop.
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
Copy link

dgrant commented Mar 14, 2013

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment