-
-
Save anonymous/1225358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks