
import java.io.*;
import java.net.*;

public class Socket1 {
  //checks which standards ports available on specified host
  public static void main(String[] args) {

    if ( args.length < 1 ) {
      System.err.println("Socket1 <hostname>");
      System.exit(1);
    }
    String server = args[0];

    InetAddress ipaddress = null;
    try {
      ipaddress = InetAddress.getByName( server );
    }
    catch( UnknownHostException exception ) {
      System.err.println( exception );
    }

    int[] standardPort = { 7,13,20,23,25,37,80,119 };
    Socket socket;

    for ( int i = 0; i < standardPort.length; ++i ) {
      try {
        socket = new Socket( ipaddress, standardPort[i] );
        socket.close();
        System.out.println( server + " port " + standardPort[i] + ": available");
      }
      catch( IOException exception ) {
        System.out.println( server + " port " + standardPort[i] + ": not available");
        continue;
      }
    }

  } // end main
}   // end Socket1
