首页 > 编程语言 > 详细

JAVA网络编程InetAddress类

时间:2020-12-11 22:33:56      阅读:28      评论:0      收藏:0      [点我收藏+]
import java.io.IOException;
import java.net.InetAddress;

public class InetAddressDemo {
    public static void main(String[] args) throws IOException {
        InetAddress locAdd = null;  //声明InetAddress对象
        InetAddress remAdd = null;  //声明InetAddress对象
        locAdd = InetAddress.getLocalHost();    //得到本地InetAddress对象
        remAdd = InetAddress.getByName("www.baidu.com");    //得到远程InetAddress对象
        InetAddress remAdd2 = InetAddress.getByName("192.168.121.200");
        System.out.println("本机IP地址:"+locAdd.getHostAddress());  //得到本地IP地址
        System.out.println("百度的IP地址"+remAdd.getHostAddress());  //得到远程IP地址
        System.out.println("本机是否可达"+remAdd.isReachable(5000));
        System.out.println("是否可达远程主机"+remAdd2.isReachable(5000));
    }
}

JAVA网络编程InetAddress类

原文:https://www.cnblogs.com/xl4ng/p/14122543.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!