InetAddress的几个常用的static方法
来源:互联网 发布:易建联体测数据 编辑:程序博客网 时间:2024/05/14 17:36
1. getAllByName(String host)
给定主机名的所有 IP 地址所组成的数组。
2. getByName(String host)
给定主机名的 IP 地址。
3. getLocalHost()
本地主机的 IP 地址。
4.getLoopbackAddress()
返回回送地址
下面给出测试程序:
package com.niepengfei.test;import java.net.InetAddress;public class TestInetAddress {public static void main(String[] args) throws Exception {InetAddress[] inetAddressArray = InetAddress.getAllByName("baidu.com");for(int i=0;i<inetAddressArray.length;i++){InetAddress addr = inetAddressArray[i];System.out.println(addr.getHostName()+" "+addr.getHostAddress());}System.out.println("-----------------------------------------------");InetAddress address = InetAddress.getByName("baidu.com");System.out.println(address.getHostName()+" "+address.getHostAddress());System.out.println("-----------------------------------------------");InetAddress locaAddress = InetAddress.getLocalHost();System.out.println(locaAddress.getHostName()+" "+locaAddress.getHostAddress());System.out.println("-----------------------------------------------");InetAddress loopbackAddress = InetAddress.getLoopbackAddress();System.out.println(loopbackAddress.getHostName()+" "+loopbackAddress.getHostAddress());}}
测试结果如下:
0 0
- InetAddress的几个常用的static方法
- InetAddress的常用方法
- InetAddress类的常用方法介绍
- InetAddress类的一些方法
- InetAddress类的一些方法
- InetAddress类的一些方法
- InetAddress创建对象的方法
- InetAddress类的一些方法
- InetAddress类的getByName()方法
- 几个常用的方法
- 几个java常用的方法
- inventDimParm 常用的几个方法
- JFrame常用的几个方法
- js几个常用的方法
- map的几个常用方法
- sqlite的几个常用方法
- UITableView 常用的几个方法
- 字符串常用的几个方法
- 为新天龙八部而生 畅游自研CycloneⅣ引擎全解析
- 【noi2010】【超级钢琴】【堆】【RMQ】
- 谓词predicate(验证email,手机号)
- struts.xml 示例配置
- linux shell脚本攻略 学习笔记3 -- 第三章 以文件之名
- InetAddress的几个常用的static方法
- 用Python中的list分片方法解决约瑟夫环问题
- WinPython升级Pip
- (2)全e化的管理系统条件-2
- 众数问题(map容器)
- #jQuery设计思想大全
- 王家林亲授《DT大数据梦工厂》大数据实战视频“Scala深入浅出实战经典”视频、音频和PPT下载!第47讲:Scala多重界定代码实战及其在Spark中的应用源码解析
- 学习easyui疑惑(四)
- java开发连接池配置方法总结