📜  java获取当前机器的IP地址-Java代码示例

📅  最后修改于: 2022-03-11 14:52:12.259000             🧑  作者: Mango

代码示例1
import java.net.DatagramSocket;
import java.net.InetAddress;

try(final DatagramSocket socket = new DatagramSocket()){
  socket.connect(InetAddress.getByName("8.8.8.8"), 10002);
  ip = socket.getLocalAddress().getHostAddress();
}