자바로 구현한 NSLookup

image 
▲ NSLookup

nslookup 명령은 유닉스나 윈도우에서 도메인 주소의 IP주소를 구하거나 IP로 도메인 주소를 알수 있게 해준다.

import java.net.*;

public class NSLookup {
    public static void main( String[] args ) {
        String addr = "withover.com";
        InetAddress inetaddr[] = null;
        try {
            inetaddr = InetAddress.getAllByName( addr );
        } catch( UnknownHostException e ) {
            e.printStackTrace();
        }
        for( int i = 0; i < inetaddr.length; i++ ) {
            System.out.println( inetaddr[i].getHostName() );
            System.out.println( inetaddr[i].getHostAddress() );
            System.out.println( inetaddr[i].toString() );
            System.out.println( "----------------------------------" );
        }
    }
}


주요 메소드

  • byte[] getAddress()
  • String getHostAddress()
  • String getHostName()

image 
▲ NSLookup.java 결과

학교에서 네트워크 수업을 듣고 있다. 네트워크도 배우고 자바도 다시 복습할 수 있는 기회가 될 듯하다.

댓글 쓰기