【Java】得到本机IP

import java.net.InetAddress;
import java.net.UnknownHostException;
 
public class MainProcess {
    public static void main(String[] args) {
        InetAddress localhost = null;
        try {
            localhost = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        System.out.println ("localhost: "+localhost.getHostAddress());
        System.out.println ("localhost: "+localhost.getHostName());
    }
}

 

posted @ 2017-09-02 21:10  Dsp Tian  阅读(376)  评论(0编辑  收藏  举报