Compare two IP addresses:

using namespace System::Net;

 

IPAddress^ ipAddr1 = IPAddress::Parse(txtIP1->Text);

IPAddress^ ipAddr2 = IPAddress::Parse(txtIP2->Text);

if(ipAddr1->Equals(ipAddr2)     // the same

{

}else{                                 // differernt

}

array<Byte>^ bytes  = ipAddr1->GetAddressBytes();
for(int i=0; i<bytes->Length; i++)
label3->Text += bytes[i];

Keyin Ip Address: 192.168.1.1

DNS to IP address

IPHostEntry^ hostEntry = nullptr;

array<String^>^ aliasList = nullptr;

array<IPaddress^>^ addrList = nullptr;

String^ strTemp = "";

try{

    hostEntry = Dns::GetHostEntry(txtHost->Text);

    aliasList = hostEntry->Aliases;

for(int i=0; i<= aliasList->Length - 1; i++)

strTemp = strTemp + aliasList[i]->ToStrig() + "";

 

Get Hostname

      try
      {
        String^ localHostName = Dns::GetHostName();
        txtHost->Text = localHostName;
      }
      catch (Exception^ ex)
      {
        Console::WriteLine(ex->StackTrace->ToString());
      }

Query result

-------------------------------------------------------------------------------------------

      IPHostEntry^ hostEntry = nullptr;
      array<IPAddress^>^ addrList = nullptr;
      String^ strTemp = "";    

      try
      {
        // 將以點分隔的DNS主機名稱或IP位址解析為IPHostEntry物件
        hostEntry = Dns::Resolve(txtHost->Text);
 
        // 主機IP位址清單
        addrList = hostEntry->AddressList;
 
        for (int i = 0; i <= addrList->Length - 1; i++)
          strTemp = strTemp + addrList[i]->ToString() + "rn";
 
        MessageBox::Show("Address List: " + "rn" + strTemp, "DNS Resolve",       MessageBoxButtons::OK, MessageBoxIcon::Information, MessageBoxDefaultButton::Button1);
      }

Download a file

String^ uri = "";

if(!txtURL->Text->StartWith("http:"))

{

    uri = "http://" + txtURL->Text;

}else{

   uri = txtRUL->Text;

}

String^ localfile = uri->Substring(uri->LastIndexOf("/") + 1);

StatusBar->Text = "Downloading file from " + uri;

WebClient^ webclient = gcnew WebClient():

try{

    NetworkCredential^ credentials = gcnew NetworkCredential("anonymous", "test@mcirosoft.com");

    webclient->Credentials = credentials;

    webclient->DownloadFile(uri, localfile);

    StatusBar->Text = "Download file from " + uri + " completed.";

   MessageBox::Show("download file completed.", "Web Client - HTTP Protocol", MessageBoxButtons::OK, MessageBoxIcon::Information);

}

圖片網址:

http://l.yimg.com/f/i/tw/hp/mh/12purple.gif

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()