HostAddress.java



import java.net.InetAddress;

/** 引数に指定したマシン名の
    IPアドレスを表示するクラス HostAddress */

public class HostAddress {

  /** 最初に呼び出されるメソッド */

     public static void main( String argv[] ) {

          try {
                InetAddress host;
                if( argv.length > 0 )
                    host = InetAddress.getByName( argv[0] );
                else
                    host = InetAddress.getLocalHost();

                System.out.println( host.getHostName()
                                  + "の IPアドレスは "
                                  + host.getHostAddress()
                                  + " です" );
          }
          catch( Exception e ){
                System.err.println( e.getMessage() );
                System.exit(-1);
          }
     }
}