我玩Java

Java 获取指定主机IP

2018-10-07  本文已影响8人  黄一倚
import java.net.InetAddress;
import java.net.UnknownHostException;

public class GetIP {
    public static void main(String[] args) {
        InetAddress address = null;
        try {
            address = InetAddress.getByName("www.baidu.com");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        System.out.println(address.getHostName()+":"+address.getHostAddress());
        System.exit(0);
    }
}
上一篇下一篇

猜你喜欢

热点阅读