Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
/**
*
* @author li
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
showNIC();
}
/**
* Gibt die Informationen über alle Netzwerkkarten aus
*
*/
public static void showNIC() {
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();
}
}
}
Netzwerk-Interface: lo (MS TCP Loopback interface)
- 127.0.0.1
Netzwerk-Interface: eth0 (Atheros AR5006X Wireless Network Adapter - Paketplaner-Miniport)
- 192.168.2.188
Netzwerk-Interface: eth1 (Realtek RTL8139-Familie-PCI-Fast Ethernet-NIC - Paketplaner-Miniport)
// Adressen durchlaufen
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
if (address.getClass().equals(Inet4Address.class)) {
System.out.println(String.format("- %s", address.getHostAddress()));
}
}
package de.tutorials.net;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
public class IPAddressExamples {
public static void main(String[] args) throws Exception {
for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) {
System.out.println(nic);
for (InterfaceAddress ifaceAddress : nic.getInterfaceAddresses()) {
InetAddress address = ifaceAddress.getAddress();
if (address instanceof Inet4Address) {
System.out.println(address);
}
}
}
Inet4Address inet4Address = getInet4Address("eth3");
System.out.println(inet4Address);
}
public static Inet4Address getInet4Address(String interfaceName) throws SocketException {
NetworkInterface nic = NetworkInterface.getByName(interfaceName);
Inet4Address inet4Address = null;
for (InterfaceAddress ifaceAddress : nic.getInterfaceAddresses()) {
InetAddress address = ifaceAddress.getAddress();
if (address instanceof Inet4Address) {
inet4Address = (Inet4Address) address;
break;
}
}
return inet4Address;
}
}