前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >InetAddress的用法

InetAddress的用法

作者头像
马克java社区
修改2021-05-11 10:05:06
9140
修改2021-05-11 10:05:06
举报
文章被收录于专栏:java大数据

InetAddress的用法 

下面这个程序利用InetAddress.getByName()来得到你的和百度IP地址。

马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。

例:2.1.1

import java.net.*;

public class TestMark_to_win {

    public static void main(String[] args) throws Exception {

        /* static InetAddress getByName(String host) Determines the IP address

of a host, given the host's name.

         */

        InetAddress a = InetAddress.getByName("localhost");

        System.out.println(a.getHostAddress());

        System.out.println(a.getHostName());

        InetAddress b = InetAddress.getByName("www.baidu.com");

        System.out.println(b.getHostAddress());

        System.out.println(b.getHostName());

    }

}

输出结果:

127.0.0.1

localhost

61.135.169.125

www.baidu.com

更多详情:https://blog.csdn.net/qq_44591615/article/details/109275753

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档