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

public class IpDemo {

    public static void main(String[] args) throws UnknownHostException {
        
        /*
         * 演示IP对象
         */
        
        InetAddress ip = InetAddress.getLocalHost() ;
        System.out.println(ip);//dell-pc/192.168.17.1
        //www.baidu.com.cn  news.baidu.com.cn
        //www表示百度的互联网主机
        //news表示百度的新闻主机
        //baidu表示主机名
        //com表示商业主机
        //cn表示中国主机
//        String ips = ip.getHostAddress(); //获取ip对象主机名的字符串表现形式
//        String name = ip.getHostName();   //获取ip对象主机地址(192.168....)的字符串表现形式
//        System.out.println(ips+":"+name);
        
        //获取其他主机的信息
        ip = InetAddress.getByName("dell-pc");
        System.out.println(ip);
        
        
    }

}

 

相关文章:

  • 2021-12-20
  • 2021-04-12
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-05-17
  • 2021-04-18
猜你喜欢
  • 2021-04-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2022-02-08
  • 2021-12-06
相关资源
相似解决方案