java之InetAddress的使用
2011-06-16 22:23
357 查看
当今社会中,网络已经成了人们工作,娱乐,生活,休闲的一部分,网络程序设计就是开发为用户提供网络服务的实用程序,例如网络通信,股票行情,新闻资讯等。另外网络程序设计也是游戏开发的必修课
主要要用到下面几个方法:
InetAddress getLocalHost();
InetAddress getByName(String host);
String getHostName();
String getHostAddress();
boolean isReachable(int timeout);
运行结果如下:
主要要用到下面几个方法:
InetAddress getLocalHost();
InetAddress getByName(String host);
String getHostName();
String getHostAddress();
boolean isReachable(int timeout);
import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; public class InetAddressDemo { public static void main(String[] args) { InetAddress localhost=null; InetAddress remote=null; try { localhost=InetAddress.getLocalHost(); System.out.println(localhost.getHostName()); System.out.println(localhost.getHostAddress()); System.out.println(localhost.isReachable(5000)); remote=InetAddress.getByName("www.google.com"); System.out.println(remote.getHostAddress()); System.out.println(remote.getHostName()); System.out.println(remote.isReachable(5000)); } catch(UnknownHostException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } } }
运行结果如下:
相关文章推荐
- java InetAddress基本使用
- java之InetAddress类和InetSocketAddress的使用
- Java InetAddress.getByAddress()的使用
- java点滴之InetAddress类和InetSocketAddress的使用
- java点滴之InetAddress类和InetSocketAddress的使用
- Java InetAddress.getByAddress()的使用
- java.net.InetAddress的使用
- Java InetAddress.getByAddress()的使用
- JAVA学习笔记-----------InetAddress 的有关IP地址的使用案例(杂乱)
- java点滴之InetAddress类和InetSocketAddress的使用
- java网络编程之InetAddress
- java二十三节-InetAddress与URL
- Java网络编程(InetAddress)
- java InetAddress.getLocalHost() 在linux里实现
- Java.UDP-TCP-DatagramSocket-DatagramPacket-InetAddress-ServerSocket-Socket
- java之InetAddress
- java常用类之——java.net.InetAddress
- Java中InetAddress 的dns cache应用问题
- Java 输出通过 InetAddress 获得的 IP 地址数组
- Java笔记(9)-网络编程、URL、InetAddress、套接字、Socket、ServerSocket、多线程、UDP、广播数据包、远程调用