static void displayInfo(NetworkInterface netint) throws IOException { inetAddresses = netint.getInterfaceAddresses(); System.out.println("some information about my link:"); System.out.printf("Display name: %s\n", netint.getDisplayName()); System.out.printf("Name: %s\n", netint.getName()); System.out.printf("Up? %s\n", netint.isUp()); System.out.printf("Loopback? %s\n", netint.isLoopback()); System.out.printf("PointToPoint? %s\n", netint.isPointToPoint()); System.out.printf("Supports multicast? %s\n", netint.supportsMulticast()); System.out.printf("Virtual? %s\n", netint.isVirtual()); System.out.printf("Hardware address: %s\n", Arrays.toString(netint.getHardwareAddress())); System.out.printf("MTU: %s\n", netint.getMTU()); System.out.printf("\n"); System.out.println( "my ip address is: " + ((InterfaceAddress) inetAddresses.get(0)).getAddress()); System.out.println( "the sunnetmask address is: " + ((InterfaceAddress) inetAddresses.get(0)).getNetworkPrefixLength()); System.out.println("the broadcast address of this subnet is:" + bcid); }
public static void showNIC() { // http://www.informatik-blog.net/2009/01/28/informationen-der-netzwerkkarten-auslesen/ try { Enumeration<NetworkInterface> interfaceNIC = NetworkInterface.getNetworkInterfaces(); // Alle Schnittstellen durchlaufen while (interfaceNIC.hasMoreElements()) { // Elemente abfragen und ausgeben NetworkInterface n = interfaceNIC.nextElement(); System.out.println( String.format("Netzwerk-Interface: %s (%s)", n.getName(), n.getDisplayName())); // Adressen abrufen Enumeration<InetAddress> addresses = n.getInetAddresses(); // Adressen durchlaufen while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); System.out.println(String.format("- %s", address.getHostAddress())); } } System.out.println(); } catch (SocketException e) { e.printStackTrace(); } }