获取本机IP地址

 


获取本机IP地址
1
2
3
4
5
6
7
8
9
10
11
12
13
package socket;
 
import java.net.InetAddress;
import java.net.UnknownHostException;
 
public class TestSocket {
 
    public static void main(String[] args) throws UnknownHostException {
        InetAddress host = InetAddress.getLocalHost();
        String ip =host.getHostAddress();
        System.out.println("本机ip地址:" + ip);
    }
}

posted on 2018-12-29 10:50  我是司  阅读(367)  评论(0编辑  收藏  举报

导航