InetAddress : IPnetworkAddress
getByName : 접속할 도메인명
getAllByName :도메인 IP정보 확인 (!배열!)
getHostAddress:IP주소(숫자)를 문자열로 반환
public static void main(String[] args) throws Exception { //server에 연결 하기위해
//InetAddress : IPnetworkAddress
//getByName : 접속할 도메인 주소명을 말합니다.
InetAddress ia = InetAddress.getByName("localhost"); //!!자기 기본 정보 확인!!
System.out.println(ia);
//System.out.println(ia.getHostName()); // 도메인 명
//System.out.println(ia.getHostAddress()); //도메인에 Ip주소
//System.out.println(ia.toString());
//getAllbyName : 도메인 IP정보 확인 (배열)
InetAddress[] ia2 = InetAddress.getAllByName("google.com");//배열
System.out.println(ia2.length); //ip4개 있음 확인
int w=0;
while(w<ia2.length) {
System.out.println(ia2[w].getHostAddress()); //다 출력
w++;
}
getHostAddress:IP주소(숫자)를 문자열로 반환
결과값 :
length로 아이티 개수와 총 아이피 주소를 확인할 수 있어요.
구글은 총1개의 주소, 네이버는 4개, 다음은 3개를 사용하네요.
728x90
'JAVA > Networking' 카테고리의 다른 글
[java/crawling] 크롤링 웹페이지 그대로 복사해오기 (0) | 2022.07.03 |
---|---|
[java/net] 인터넷 URL 이미지 주소를 이용하여 이미지를 내 pc에 copy하기 (0) | 2022.06.27 |
[java/net] 인터넷 URL 이미지 주소로 파일 크기/형태 확인 URLConnection/openConnection (0) | 2022.06.27 |
댓글