Exemple #1
0
  /// <summary>Main()</summary>
  public static void Main
  ( 
   string[] argv
  )
  {
   Boolean               booleanParseCommandLineArguments      =  false;
   string                exceptionMessage                      =  null;     
   StringBuilder[][]     sb                                    =  null;
   UtilityWhoIsArgument  utilityWhoIsArgument                  =  null;
   
   utilityWhoIsArgument = new UtilityWhoIsArgument();
   
   booleanParseCommandLineArguments =  UtilityParseCommandLineArgument.ParseCommandLineArguments
   ( 
    argv, 
    utilityWhoIsArgument
   );

   if ( booleanParseCommandLineArguments == false )
   {
    // error encountered in arguments. Display usage message
    System.Console.Write
    (
     UtilityParseCommandLineArgument.CommandLineArgumentsUsage( typeof ( UtilityWhoIsArgument ) )
    );
    return;
   }//if ( booleanParseCommandLineArguments  == false )
   WhoisLookup
   (
    ref utilityWhoIsArgument,
    ref sb,
    ref exceptionMessage
   );
  }//public static void Main()
  }//public void ButtonReset_Click()

  /// <summary>WhoIsLookup</summary>
  public void WhoIsLookup()
  {
   string                exceptionMessage      =  null;
   string[]              registry              =  null;
   StringBuilder[][]     sbWhoIs               =  null;
   StringBuilder         sbJoin                =  null;
   UtilityWhoIsArgument  utilityWhoIsArgument  =  null;
   try
   {
    UtilityWebControl.SelectedItem( ListBoxRegistry, ref registry  );
    utilityWhoIsArgument  =  new UtilityWhoIsArgument
                             (
                              RegistryDomainSuffixOnly,
                              PortWhoIs,
                              new string[] { DomainName },
                              registry
                             );
    UtilityWhoIs.WhoisLookup
    (
     ref utilityWhoIsArgument,
     ref sbWhoIs,
     ref exceptionMessage
    );
    if ( exceptionMessage != null ) { Feedback = exceptionMessage; return; }
    sbJoin = new StringBuilder();
    for ( int indexDimension1 = 0; indexDimension1 < sbWhoIs.Length; ++indexDimension1 )
    {
     for ( int indexDimension2 = 0; indexDimension2 < sbWhoIs[indexDimension1].Length; ++indexDimension2 )
     {
      sbJoin.Append( sbWhoIs[indexDimension1][indexDimension2] );
     }//for ( int indexDimension2 = 0; indexDimension2 < sb[indexDimension1].Length; ++indexDimension2 )
    }//for ( int indexDimension1 = 0; indexDimension1 < sb.Length; ++indexDimension1 )  
   }//try
   catch ( Exception exception ) { exceptionMessage = exception.Message; }
   if ( exceptionMessage != null )
   {
   	Feedback = exceptionMessage;
   }
   Feedback = sbJoin.ToString();
  }//public void WhoIsLookup
Exemple #3
0
  }//public static void Main()

  ///<summary>WhoisLookup</summary>
  public static void WhoisLookup
  (
   ref UtilityWhoIsArgument utilityWhoIsArgument,
   ref StringBuilder[][]    sb,
   ref string               exceptionMessage
  )
  {
   byte[]        domainNameByte            =  null;
   bool          registryDomainSuffixOnly  =  false;
   int           domainIndex               =  -1;
   int           registryIndex             =  -1;
   string        domainName                =  null;
   string        domainNameNewLine         =  null;
   string[]      domainNameSplit           =  null;
   string        readLine                  =  null;
   string[]      registry                  =  null;
   string        registryCurrent           =  null;
   HttpContext   httpContext               =  HttpContext.Current;
   Stream        stream                    =  null;
   StreamReader  streamReader              =  null;
   TcpClient     tcpClient                 =  null;
   try
   {
   	if ( utilityWhoIsArgument.registry.Length > 0 )
   	{
     registry = utilityWhoIsArgument.registry;
    }
    else if ( utilityWhoIsArgument.registryDomainSuffixOnly == false )
    {
     UtilityString.ArrayCopy( RegistryWhoIs, ref registry, RankRegistryWhoIsName, ref exceptionMessage );
     if ( exceptionMessage != null ) { return; }    	
    }
    else
    {
     registryDomainSuffixOnly = true;
    }
    sb = new StringBuilder[utilityWhoIsArgument.domainName.Length][];
    for ( domainIndex = 0; domainIndex < utilityWhoIsArgument.domainName.Length; ++domainIndex )
    {
     domainName         =  utilityWhoIsArgument.domainName[domainIndex];
     domainNameNewLine  =  domainName + Environment.NewLine;
     domainNameByte     =  Encoding.ASCII.GetBytes( domainNameNewLine.ToCharArray() );
     if ( registryDomainSuffixOnly )
     {
      domainNameSplit  =  domainName.Split('.');
      registry         =  new string[1];
      registry[0]      =  RegistryWhoIs[0][RankRegistryWhoIsName];
      for ( int index = 0; index < RegistryWhoIs.Length; ++index )
      {
       if ( RegistryWhoIs[index][RankRegistryWhoIsName].EndsWith( domainNameSplit[domainNameSplit.Length-1].ToLower() ) ) 
       {
       	registry[0] = RegistryWhoIs[index][RankRegistryWhoIsName];
       	break;
       }//if ( RegistryWhoIs[index][RankRegistryWhoIsName].EndsWith( domainNameSplit[domainNameSplit.Length-1].ToLower() );
      }//for ( int index = 0; index < RegistryWhoIs.Length; ++index )
     }//if ( registryDomainSuffixOnly == true )
     sb[domainIndex] = new StringBuilder[registry.Length];
     for ( registryIndex = 0; registryIndex < registry.Length; ++registryIndex )
     {
      registryCurrent                 =  registry[registryIndex]; 
      tcpClient                       =  new TcpClient( registryCurrent, utilityWhoIsArgument.port );
      stream                          =  tcpClient.GetStream();
      stream.Write( domainNameByte, 0, domainNameNewLine.Length );
      streamReader                    =  new StreamReader( tcpClient.GetStream(), Encoding.ASCII );
      sb[domainIndex][registryIndex]  =  new StringBuilder( registryCurrent);
      if ( httpContext == null ) 
      { sb[domainIndex][registryIndex].Append( Environment.NewLine ); }
      else
      { sb[domainIndex][registryIndex].Append( "<br/>" ); }      
      while ( true )
      {
	   readLine  =  streamReader.ReadLine();
	   if ( readLine == null ) { break; }
       if ( httpContext == null ) { System.Console.WriteLine( readLine ); }
	   sb[domainIndex][registryIndex].Append( readLine );
	   if ( httpContext != null ) { sb[domainIndex][registryIndex].Append("<br/>"); }
	  }//while ( true )
	  tcpClient.Close();
     }//for ( registryIndex = 0; registryIndex < registry.Length; ++registryIndex ) 
    }//foreach ( string domainName in utilityWhoIsArgument.domainName )    	
   }//try
   catch ( SocketException exception ) { UtilityException.ExceptionLog( exception, exception.GetType().Name, ref exceptionMessage ); }
   catch ( Exception exception ) { UtilityException.ExceptionLog( exception, exception.GetType().Name, ref exceptionMessage ); }
   finally 
   {
   	if ( tcpClient != null ) { tcpClient.Close(); }
   }//finally	
  }//WhoisLookup