So erhalten Sie die Server-IP-Adresse in Java
In Java können SieInetAddress.getLocalHost() verwenden, um die IP-Adresse des aktuellen Servers abzurufen, auf dem die Java-App ausgeführt wird.
package com.example;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class Test {
public static void main(String[] args) {
InetAddress ip;
try {
ip = InetAddress.getLocalHost();
System.out.println("Current IP address : " + ip.getHostAddress());
} catch (UnknownHostException e) {
e.e.printStackTrace();
}
}
}
Ausgabe
Current IP address : 192.168.1.22