public
anonymous / 2
Last active

  • Download Gist
2
1 2 3 4 5 6 7 8 9 10
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)
Test11.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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");
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.