InetAddress 테스트
5802 단어 InetAddress
package com.ddc.gemantic;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class InetAddressTestMain {
/** InetAddress
* : 、 、ip 、ipv4、ipv6
* InetAddress
* InetAddress , 3 : 、 、 ip
* ip , ip( ), ip( web ), ip ( web )
* : , ,DNS IP
*
* @param args
* @throws UnknownHostException
*/
public static void main(String[] args) throws UnknownHostException {
System.out.println(" InetAddress.getByName(host) InetAddress.getAllByName(host) ");
//InetAddress.getByName(host) InetAddress.getAllByName(host) , InetAddress.getAllByName(host)
//InetAddress.getAllByName(host) : ( )、 、ip (ipv4:192.168.1.235 ipv6)
/* InetAddress , :www.google.com
* 1、 , DNS, ,
* 2、 , 。
* 3、 ip, InetAddress
*/
InetAddress[] googleAddressList=InetAddress.getAllByName("www.google.com");
for(InetAddress add:googleAddressList)
System.out.println("ip :"+add.getHostAddress()+" ( ) :"+add.getHostName()+" :"+add.getCanonicalHostName());
/*
* InetAddress , hx-in-f147.1e100.net(google )
* 1、 : , DNS, ,
* 2、 hx-in-f147.1e100.net
* 3、 ip
*/
InetAddress[] googleReallyHostAddressList=InetAddress.getAllByName("hx-in-f147.1e100.net");
for(InetAddress add:googleReallyHostAddressList)
System.out.println("ip :"+add.getHostAddress()+" ( ) :"+add.getHostName()+" :"+add.getCanonicalHostName());
/*
* ip InetAddress
* 1、 DNS
* 2、 :InetAddress canonicalHostName hostName , get , DNS
* 3、 , DNS, ip
*/
InetAddress[] ipAddressList=InetAddress.getAllByName("74.125.71.99");
for(InetAddress add:ipAddressList)
System.out.println("ip :"+add.getHostAddress()+" ( ) :"+add.getHostName()+" :"+add.getCanonicalHostName());
System.out.println("InetAddress.getByAddress(addr) ;");
/**
* InetAddress.getAllByName() , ip 。
*/
InetAddress byteAddress=InetAddress.getByAddress(ipAddressList[0].getAddress());
System.out.println("ip :"+byteAddress.getHostAddress()+" ( ) :"+byteAddress.getHostName()+" :"+byteAddress.getCanonicalHostName());
/**
* ip InetAddress, ,ip 。
* getCanonicalHostName() 。
*/
InetAddress allInetAddress=InetAddress.getByAddress("hx-in-f147.1e100.net", ipAddressList[0].getAddress());
System.out.println("ip :"+allInetAddress.getHostAddress()+" ( ) :"+allInetAddress.getHostName()+" :"+allInetAddress.getCanonicalHostName());
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
InetAddress 테스트텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.