دانلود - آموزش - سورس کد - کنکور - برنامه

دانلود - آموزش - سورس کد - کنکور - برنامه

دانلود - آموزش - سورس کد - کنکور - برنامه

دانلود - آموزش - سورس کد - کنکور - برنامه

Whois Lookup در C#.Net

در این پروژه به شما نشان داده می شود که چطور می توان یک سیستم Whois Lookup که کاربران بوسیله آن بتوانند اطلاعات یک دومین را جستجو کنند. این پروژه بصورت Windows Application پیاده سازی شده است. می توان براحتی آنرا به Asp.net تبدیل کنید و در سایتان استفاده نمائید. 

using System;
using
System.Net;
using
System.Net.Sockets;
using
System.Text;
 


namespace Whois
{

a

public delegate void WhoisEventHandler(object sender,WhoisEventArgs e);

      ///

      /// Our class containing information to be passed to      /// the lookup event.      ///

کلاس حاوی اطلاعاتی که به رخداد (event) lookup ارسال می شود

      public class WhoisEventArgs : EventArgs
      {

            public string WhoisInfo
            {

                  get                  {
                        return this.whoisInfo;
                  }
            }

 

آدرس سروری که اطلاعات دومین در آن جستجو(lookup) می شود.

            public string WhoisServer
            {
                  get                  {
                        return this.whoisServer;
                  }

            } 
            private string whoisInfo;
            private string whoisServer;

            public WhoisEventArgs(string Info,string Server)
            {
                  this.whoisInfo = Info;
                  this.whoisServer = Server;
            }

      }

 

      ///

      /// Perform a whois lookup on a domain name, enabling you to       /// find out if a domain name is registered, and if it is -       /// to whom and what name servers it uses.      ///

بوسیله این کلاس می توانید جستجو کنید که آیا یک دومین ثبت شده است و اگر ثبت شده توسط چه کسی و چه زمانی و چه خدماتی می دهد.

 

      public class Whois     
}

            ///

            /// The server used to perform the whois. If this is not set,            /// then an attempt to find the whois server automatically is            /// made. If none is found, the internic whois server is used            /// by default.            ///

 

آدرس سروری که اطلاعات دومین در آن جستجو(lookup) می شود.

 public string WhoisServer
 {

                  get                  }                       ; return this.whoisServer 
{

 set     {

       this.whoisServer = value;

  }

 }

 

            ///

            /// Called when the lookup has been complete.            ///

زمانیکه عمل جستجو تمام شود این رخداد صدا می شود.

    public event WhoisEventHandler LookupComplete;

 private string whoisServer = "";

             ///

            /// Performs a whois lookup on the domain provided.            ///

            ///

 
 

The domain to lookup.
            /// Information returned by the domain whois server,            /// which can then be string parsed to see if the domain is available or taken.

 

بوسیله این متد می توانید یک دومین را جستجو کند. نام دومین را با پارامتر  Domain بدهید.

    public void Lookup(string Domain)
    {

نتیجه جستجو در این متغییر نگهداری می شود.

     string result = "";
     string[] parts = new string[] {};
 

                  // Knock off http and www if it's in the Domain

اگر ابتدای دومین با http:// شروع شده باشد آنرا حذف می کند چون هنگام جستجوی دومین باید نام دومین بدون http:// باشد

                  if ( Domain.StartsWith("http://") )
                  {

                        Domain = Domain.Replace("http://","");

                  }

اگر ابتدای دومین با www. شروع شده باشد آنرا حذف می کند چون هنگام جستجوی دومین باید نام دومین بدون www. باشد

                  if ( Domain.StartsWith("www.") )
                  {
                   Domain = Domain.Substring(4,Domain.Length -4);
                  }

                 

                  if ( Domain.IndexOf(".tv") != -1 || Domain.IndexOf(".pro") != -1 || Domain.IndexOf(".name") != -1)

                  {

                        // As result says - certain domain authorities like to keep their whois service private.

                        // There maybe extra tlds to add.

اگر دومین از نوع .tv .pro .name باشد به کاربر اخطار می دهد که این دومین ها به حساب کاربری نیاز دارند.

                         result = "'.pro','.name', and '.tv' domains require an account for a whois";

                  }
                  else                  {

حتما باید نام دومین . (نقطه) داشته باشد مانند nofa.ir

                        if ( Domain.IndexOf(".") != -1 )
                        {

                              // Find the whois server for the domain ourselves, if non set.

                              if ( this.whoisServer == "" )
                              {

اگر آدرس سرور whois را نداده باشید سیستم آدرس سرور را قرار می دهد

                                    this.whoisServer = this.getWhoisServer(Domain);

                              } }

 

                              // Connect to the whois server

در این قسمت از طریق پورت 43 به سرور whois متصل می شود.

43 پورتی است که سرور های whois از آن استفاده می کند.

                              TcpClient tcpClient = new TcpClient();
                              tcpClient.Connect(this.whoisServer,43);
                              NetworkStream networkStream  = tcpClient.GetStream();

                              // Send the domain name to the whois server

در این قسمت نام دومین به سرور whois ارسال می گردد.

                              byte[] buffer = ASCIIEncoding.ASCII.GetBytes(Domain + "\r\n");
                              networkStream.Write(buffer,0,buffer.Length);

                              // Read back the results

در این قسمت جواب های سرور whois خوانده می شود. این جوابها به اندازه 8192 بایت بافر می شود.

                              buffer = = new byte[8192];
                              int i = networkStream.Read(buffer,0,buffer.Length);
                              while ( i > 0)
                              { {

                                    i = networkStream.Read(buffer,0,buffer.Length);
                                    result += ASCIIEncoding.ASCII.GetString(buffer);;

                              }

                              networkStream.Close();
                              tcpClient.Close();

                        } }

                        else                        {    

                              result = "Please enter a valid domain name.";

                        }

                  }

 

                  // Fire event with the info of the lookup

در این قسمت رخداد پایان رسیدن جستجو صدا می شود.

                  if ( this.LookupComplete != null )

                  {

                        WhoisEventArgs whoisEventArgs = new WhoisEventArgs(result,this.whoisServer);

                        this.LookupComplete(this,whoisEventArgs);

                  }

            }

 

            ///

            /// Gets the whois server for a domain using

            /// whois-servers.net.

            ///

            ///

 
 

The domain name to retrieve the whois server for.

 

            /// The whois server hostname.

 

در این متد اگر آدرس سرور whois داده نشده باشد .سیستم به صورت اتوماتیک بدنبال سرور whois می گردد و از آن استفاده می کند. اگر سروری پیدا نکند از سرور inetrnic استفاده می کند.

            private string getWhoisServer(string domainName)

            {

                  string [] parts = domainName.Split('.');

                  string tld = parts[parts.Length -1];

                  string host = tld + ".whois-servers.net";

 

                  // .tk doesn't resolve, but it's whois server is public

                  if ( tld == "tk")

                  {

                        return "whois.dot.tk";

                  }

 

                  try

                  {

 IPHostEntry ipHostEntry = Dns.GetHostByName(host);

 

                        if ( ipHostEntry.HostName ==  host )

                        {

                              // No entry found, use internic as default

                              host = "whois.internic.net";

                        }

                        else

                        {

                              host = ipHostEntry.HostName;

                        }

 

                        return host;

                  }

                  catch

                  {

                        host = "whois.internic.net";

                        return host;

                  }

            }

      }

}

 
منبع :  nofa.ir
نظرات 1 + ارسال نظر
hassan پنج‌شنبه 5 آذر‌ماه سال 1394 ساعت 01:51 ق.ظ

سلام و خسته نباشید...
نمیشه سورس این مطلب رو برام بفرستید؟
ممنون

برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد