国产黄色免费网站,人人干人人干人人干,免费大黄网站在线看,国产情侣一区二区三区,99精品国产福利免费一区二区,国产亚洲成归v人片在线观看,伊人88

2023信創(chuàng)獨(dú)角獸企業(yè)100強(qiáng)
全世界各行各業(yè)聯(lián)合起來(lái),internet一定要實(shí)現(xiàn)!

利用c#實(shí)現(xiàn)對(duì)sql server的信息探測(cè)

2004-02-11 eNet&Ciweek

  1、原理簡(jiǎn)述  

  對(duì)于SQL Server2000來(lái)說(shuō),打開(kāi)SQL Server客戶(hù)端準(zhǔn)備連接,當(dāng)拉開(kāi)服務(wù)器列表的時(shí)候,整個(gè)局域網(wǎng)所有的SQL Server服務(wù)器都被列出來(lái)了。這是為什么呢?

  原理如下:

  從我自己的機(jī)器(192.168.0.1)上從1434端口廣播(192.168.0.255)了這個(gè)UDP包,然后,整個(gè)局域網(wǎng)中的SQL Server服務(wù)器都開(kāi)始響應(yīng)這個(gè)UDP數(shù)據(jù)包,所有這些都是明文傳輸?shù)?,我們可以很容易探測(cè)一個(gè)IP地址的1434端口,獲得該IP地址上運(yùn)行的SQL Server的相關(guān)信息?! ?

  這些信息包括:主機(jī)名稱(chēng)、實(shí)例名稱(chēng)、版本、管道名稱(chēng)以及使用的端口等。這個(gè)端口是微軟自己使用,而且不象默認(rèn)的1433端口那樣可以改變,1434是不能改變的?! ?

  2、程序?qū)崿F(xiàn)  

  下面是一個(gè)利用1434進(jìn)行探測(cè)的c#程序,核心代碼如下(很簡(jiǎn)單,呵呵) :

  using System;

  using System.Net.Sockets;

  using System.Net;

  using System.Text;

  using System.Threading;

  namespace ConsoleApplication3

  { 

  class Class1

  {

  //創(chuàng)建一個(gè)UDPCLIENT實(shí)例

  private static UdpClient m_Client;  

  //LISTEN用來(lái)獲取返回的信息

  public static string Listen(string hostip)

  {

  string HostIP = hostip;

  IPAddress thisIP = IPAddress.Parse(HostIP);

  IPEndPoint host = new IPEndPoint(thisIP,1434);

  byte [] data = m_Client.Receive(ref host);

  Encoding ASCII = Encoding.ASCII;

  String strData = ASCII.GetString(data);

  return strData;  

  }

  //SEND

  public static void Send(string hostip)

  {

  string HostIP = hostip;

  byte [] buffer = {02};

  //02為要發(fā)送的數(shù)據(jù),只有02、03、04有回應(yīng)

  int ecode = m_Client.Send(buffer,1,HostIP,1434);

  //ecode用來(lái)返回是否成功發(fā)送

  if(ecode <= 0)

  {

  Console.WriteLine("發(fā)送時(shí)出錯(cuò):" + ecode);  

  }  

  }

  //對(duì)返回的信息的簡(jiǎn)單的處理

  public static void OutputInfo(string strdata)

  {

  string str = strdata;

  //str.le

  char [] that = {‘;‘,‘;‘};

  string [] strofthis =str.Split(that);

  //int i= 0 ;

  for(int i=0;i

  {

  Console.Write(strofthis[i]);

  Console.Write(‘\n‘);

  }

  

  }

  //輸入IP

  public static string InputHostIP()

  {

  Console.Write("enter the ip you want to scan:\n\n");

  string hostip =Console.ReadLine();

  Console.Write(‘\n‘);

  return hostip;

  }

  //EXIT

  public static void Exit()

  {

  Console.WriteLine("if you want to exit ,just input 1\n");

  int a = Console.Read();

  if(a!= 1)

  {

  Console.WriteLine("if you want to exit ,just input 1\n");

  Console.Read();

  }

  else

  {

  }

  }

  [STAThread]

  

  static void Main(string[] args)

  {

  string HostIP;

  HostIP = InputHostIP();

  Console.WriteLine("Begin to send udp to the host");

  m_Client = new UdpClient();

  Send(HostIP);

  string strData=Listen(HostIP);

  OutputInfo(strData);

  Exit();

  }

  }

  }

  3一個(gè)典型的返回的信息  

  ServerName;AWEN;

  InstanceName;AWEN;

  IsClustered;No;

  Version;8.00.194;

  tcp;1044; (TCP的端口,可見(jiàn)就算改了端口也是很容易找到的)

  np;\\AWEN\pipe\MSSQL$XHT310\sql\query;

相關(guān)頻道: eNews

您對(duì)本文或本站有任何意見(jiàn),請(qǐng)?jiān)谙路教峤唬x謝!

投稿信箱:tougao@enet16.com