网络编程

                                                                                              网络编程


java.net 
类 InetAddress

java.lang.Object
  继承者 java.net.InetAddress
所有已实现的接口:
Serializable
直接已知子类:
Inet4AddressInet6Address
方法摘要
 booleanequals(Object obj) 
          将此对象与指定对象比较。
 byte[]getAddress() 
          返回此 InetAddress 对象的原始 IP 地址。
static InetAddress[]getAllByName(String host) 
          在给定主机名的情况下,根据系统上配置的名称服务返回其 IP 地址所组成的数组。
static InetAddressgetByAddress(byte[] addr) 
          在给定原始 IP 地址的情况下,返回 InetAddress 对象。
static InetAddressgetByAddress(String host, byte[] addr) 
          根据提供的主机名和 IP 地址创建 InetAddress。
static InetAddressgetByName(String host) 
          在给定主机名的情况下确定主机的 IP 地址。
 StringgetCanonicalHostName() 
          获取此 IP 地址的完全限定域名。
 StringgetHostAddress() 
          返回 IP 地址字符串(以文本表现形式)。
 StringgetHostName() 
          获取此 IP 地址的主机名。
static InetAddressgetLocalHost() 
          返回本地主机。
 inthashCode() 
          返回此 IP 地址的哈希码。
 booleanisAnyLocalAddress() 
          检查 InetAddress 是否是通配符地址的实用例行程序。
 booleanisLinkLocalAddress() 
          检查 InetAddress 是否是链接本地地址的实用例行程序。
 booleanisLoopbackAddress() 
          检查 InetAddress 是否是回送地址的实用例行程序。
 booleanisMCGlobal() 
          检查多播地址是否具有全局域的实用例行程序。
 booleanisMCLinkLocal() 
          检查多播地址是否具有链接范围的实用例行程序。
 booleanisMCNodeLocal() 
          检查多播地址是否具有节点范围的实用例行程序。
 booleanisMCOrgLocal() 
          检查多播地址是否具有组织范围的实用例行程序。
 booleanisMCSiteLocal() 
          检查多播地址是否具有站点范围的实用例行程序。
 booleanisMulticastAddress() 
          检查 InetAddress 是否是 IP 多播地址的实用例行程序。
 booleanisReachable(int timeout) 
          测试是否可以达到该地址。
 booleanisReachable(NetworkInterface netif, int ttl, int timeout) 
          测试是否可以达到该地址。
 booleanisSiteLocalAddress() 
          检查 InetAddress 是否是站点本地地址的实用例行程序。
 StringtoString() 
          将此 IP 地址转换为 String


package com.net;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IpDemo {
public static void main(String[] args) throws UnknownHostException {
	InetAddress i = InetAddress.getLocalHost();
	System.out.println(i);
	System.out.println(i.toString());
	System.out.println(i.getHostAddress());
	System.out.println(i.getHostName());
	
	//InetAddress byName = InetAddress.getByName("192.168.1.104");
	InetAddress byName = InetAddress.getByName("www.baidu.com");
	System.out.println(" ---"+byName.getHostName());
	System.out.println(" ---"+byName.getHostAddress());
}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值