博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取服务器ip
阅读量:7189 次
发布时间:2019-06-29

本文共 888 字,大约阅读时间需要 2 分钟。

hot3.png

public static void main(String[] args) {    try {        InetAddress address = InetAddress.getLocalHost();//获取的是本地的IP地址 //PC-20140317PXKX/192.168.0.121        String hostAddress = address.getHostAddress(); //192.168.85.7        System.out.println("本地:"+hostAddress);        InetAddress address1 = InetAddress.getByName("my.oschina.net");//获取的是该网站的ip地址,比如我们所有的请求都通过nginx的,所以这里获取到的其实是nginx服务器的IP地        String hostAddress1 = address1.getHostAddress();//139.199.91.153        System.out.println(hostAddress1);        InetAddress[] addresses = InetAddress.getAllByName("www.baidu.com");//根据主机名返回其可能的所有InetAddress对象        for(InetAddress addr:addresses){            System.out.println(addr);//www.baidu.com/14.215.177.38            //www.baidu.com/14.215.177.37        }    } catch (UnknownHostException e) {        e.printStackTrace();    }}

转载于:https://my.oschina.net/u/728453/blog/1574013

你可能感兴趣的文章
JSON数据格式
查看>>
页面引入(include)方式的研究及性能比较
查看>>
文件操作
查看>>
前端模板基础-1
查看>>
【转】中间代码opcode的执行
查看>>
android sdk
查看>>
快速幂取模
查看>>
centos7/centos6修改系统默认语言
查看>>
Ubuntu中设置环境变量详解
查看>>
SQL Server性能优化(2)获取基本信息
查看>>
案例二(构建双主高可用HAProxy负载均衡系统)
查看>>
Memcache安装
查看>>
Session 和 Cookie
查看>>
UWP 动画
查看>>
simple introduction to UNIQ
查看>>
web和数据迁移之后出现网站后台无法登录的情况解决
查看>>
各种文件系统支持的最大硬盘容量
查看>>
[Python]学习基础篇:常见的Python内置函数及模块
查看>>
我的友情链接
查看>>
FileBeat6.4 快速上手
查看>>