标题:使用InetAddress类的方法获取http://www.hunnu.edu.cn/的主机的IP地址;获取 ...
只看楼主
云团
Rank: 2
等 级:论坛游民
帖 子:36
专家分:41
注 册:2017-1-9
结帖率:50%
已结贴  问题点数:20 回复次数:2 
使用InetAddress类的方法获取http://www.hunnu.edu.cn/的主机的IP地址;获取本地机的名称和IP地址。
大佬帮忙看看哪里有问题!!!
程序代码:
import *;

public class InetAdressTest {
    public static void main(String[] args){
        InetAddress address;
        try {
            address = InetAddress.getByName("http://www.hunnu.);
            String Hostaddr1 = address.getHostAddress();
            System.out.println("主机IP:" + Hostaddr1);
            address = InetAddress.getLocalHost();
            String HostName = address.getHostName();
            String Hostaddr2 = address.getHostAddress();
            System.out.println("本地主机名:" + HostName);
            System.out.println("本地主机IP:" + Hostaddr2);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}


搜索更多相关主题的帖子: 获取 主机 IP 地址 address 
2019-01-11 15:35
liumq235
Rank: 2
等 级:论坛游民
威 望:3
帖 子:9
专家分:27
注 册:2017-2-2
得分:10 
package test;

import
import

public class Test {
     public static void main(String[] args) throws UnknownHostException{
         
         //获取指定域名ip
         InetAddress inetAddress = InetAddress.getByName("www.baidu.com");
         System.out.println(inetAddress.getHostAddress());
         //获取本机ip
         InetAddress inetAddress2 = InetAddress.getLocalHost();
         System.out.println(inetAddress2.getHostAddress());
     }
            
}
2019-01-17 23:16
疯狂的小a
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:39
帖 子:423
专家分:1871
注 册:2018-2-6
得分:10 
程序代码:
import import public class InetAdressTest {
    public static void main(String[] args){
        InetAddress address;
        try {
            address = InetAddress.getByName("www.hunnu.);
            String Hostaddr1 = address.getHostAddress();
            System.out.println("主机IP:" + Hostaddr1);
            address = InetAddress.getLocalHost();
            String HostName = address.getHostName();
            String Hostaddr2 = address.getHostAddress();
            System.out.println("本地主机名:" + HostName);
            System.out.println("本地主机IP:" + Hostaddr2);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}

把htttp去掉就可以了

假如人生没有梦想,和咸鱼有什么区别!
2019-01-18 11:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-492636-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.457882 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved