JAVA获取本机的IP地址

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressInUse {
      public static void main(String[] args){
    try {
        InetAddress ip4 = Inet4Address.getLocalHost();
        System.out.println(ip4.getHostAddress());
        } catch (UnknownHostException e) {
          e.printStackTrace();
      }
   }
}

posted @ 2022-01-13 13:32  Aoul  阅读(440)  评论(0编辑  收藏  举报