/*
 * ResolverTest
 * 入力されたドメイン名のIPアドレスを調べる
 */
package org.logical_paradox.rss.test.resolv;

import java.net.InetAddress;

import org.logical_paradox.common.net.IPAddressRangeSet;
import org.logical_paradox.common.net.IPAddressRangeSetFactory;

public class ResolverTest {
	public static void main( String[] args ) throws Exception {
		if( args.length == 0 ) {
			System.err.println( "usage: java ResolverTest [server name1 [server name2 [server name3..]]]" );
			return;
		}

		IPAddressRangeSet rangeSet = IPAddressRangeSetFactory.getIPAddressRangeSet();
		rangeSet.load( "conf/test/resolv/ipaddresses_range.JP" );

		for( int i = 0; i < args.length; i++ ) {
			String serverName = args[i];
			InetAddress ip = InetAddress.getByName( serverName );
			byte[] b = ip.getAddress();
			System.err.print( serverName + " = " );
			for( int cnt = 0; cnt < b.length; cnt++ ) {
				System.err.print( (b[cnt] < 0 ? 256 + (int)b[cnt] : (int)b[cnt]) + " " );
			}

			System.err.println( rangeSet.includes( ip ) == true ? " OK " : " NG " );
		}
	}
}

// end of ResolverTest.java
