線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1862
推到 Plurk!
推到 Facebook!

ipconfig/all

尚未結案
luckfox
一般會員


發表:34
回覆:40
積分:24
註冊:2002-10-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-03-09 14:02:08 IP:218.32.xxx.xxx 未訂閱
請問一下,如何取得類似ipconfig/all下的所有資料,當然 adpater可能不只有一張,我應該呼叫哪些API
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-03-09 19:17:02 IP:61.218.xxx.xxx 未訂閱
lukfox您好:    包子兄的作品-----取得網路卡的相關設定  http://delphi.ktop.com.tw/topic.php?TOPIC_ID=39424    
Unit1.cpp    //---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "Unit1.h"
#include "Iphlpapi.h"    //---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
   Memo1->Lines->Clear();       ULONG ulLen1=4096;
   BYTE *pbBuf1=new BYTE[ulLen1];
   IP_ADAPTER_INFO *pipai=NULL;
   ULONG ulLen2=4096;
   BYTE *pbBuf2=new BYTE[ulLen2];
   IP_PER_ADAPTER_INFO *pippai=NULL;
   AnsiString szTemp;
   IP_ADDR_STRING *pipas=NULL;       if(ERROR_SUCCESS==GetAdaptersInfo((IP_ADAPTER_INFO*)pbBuf1, &ulLen1))
   {
      pipai=(IP_ADAPTER_INFO*)pbBuf1;
      do
      {
         //---------------------------------------------------------------------
         // Name
         Memo1->Lines->Add("AdapterName="+(AnsiString)pipai->AdapterName);             //---------------------------------------------------------------------
         // Description
         Memo1->Lines->Add("Description="+(AnsiString)pipai->Description);             //---------------------------------------------------------------------
         // Mac ID
         szTemp.sprintf("X:X:X:X:X:X",
            pipai->Address[0], pipai->Address[1], pipai->Address[2],
            pipai->Address[3], pipai->Address[4], pipai->Address[5]);
         Memo1->Lines->Add("Address="+szTemp);             //---------------------------------------------------------------------
         // Interface index
         Memo1->Lines->Add("Index="+IntToStr(pipai->Index));             //---------------------------------------------------------------------
         // Adapter type
         Memo1->Lines->Add("Type="+IntToStr(pipai->Type));             //---------------------------------------------------------------------
         // DHCP is enabled or not
         Memo1->Lines->Add("DhcpEnabled="+IntToStr(pipai->DhcpEnabled));             //---------------------------------------------------------------------
         // IP address
         pipas=&(pipai->IpAddressList);
         while(pipas!=NULL)
         {
            Memo1->Lines->Add("IpAddressList="+(AnsiString)pipas->IpAddress.String);
            pipas=pipas->Next;
         }             //---------------------------------------------------------------------
         // IP mask
         Memo1->Lines->Add("IpMask="+(AnsiString)pipai->IpAddressList.IpMask.String);             //---------------------------------------------------------------------
         // Gateway
         pipas=&(pipai->GatewayList);
         while(pipas!=NULL)
         {
            Memo1->Lines->Add("GatewayList="+(AnsiString)pipas->IpAddress.String);
            pipas=pipas->Next;
         }             //---------------------------------------------------------------------
         // DHCP server address
         Memo1->Lines->Add("DhcpServer="+(AnsiString)pipai->DhcpServer.IpAddress.String);             if(ERROR_SUCCESS==GetPerAdapterInfo(pipai->Index, (IP_PER_ADAPTER_INFO*)pbBuf2, &ulLen2))
         {
            pippai=(IP_PER_ADAPTER_INFO*)pbBuf2;
            Memo1->Lines->Add("AutoconfigEnabled="+IntToStr(pippai->AutoconfigEnabled));
            Memo1->Lines->Add("AutoconfigActive="+IntToStr(pippai->AutoconfigActive));                //------------------------------------------------------------------
            // DNS server address
            pipas=&(pippai->DnsServerList);
            while(pipas!=NULL)
            {
               Memo1->Lines->Add("DnsServerList="+(AnsiString)pipas->IpAddress.String);
               pipas=pipas->Next;
            }
         }             //---------------------------------------------------------------------
         // Have wins or not
         szTemp=(pipai->HaveWins)? "true": "false";
         Memo1->Lines->Add("HaveWins="+szTemp);             //---------------------------------------------------------------------
         // Primary wins server address
         Memo1->Lines->Add("PrimaryWinsServer="+(AnsiString)pipai->PrimaryWinsServer.IpAddress.String);             //---------------------------------------------------------------------
         // Secondary wins server address
         Memo1->Lines->Add("SecondaryWinsServer="+(AnsiString)pipai->SecondaryWinsServer.IpAddress.String);
         Memo1->Lines->Add("");             pipai=pipai->Next;             ZeroMemory(pbBuf2, ulLen2);
      } while(pipai!=NULL);
   }
   delete pbBuf2;
   delete pbBuf1;
}
//---------------------------------------------------------------------------    Unit1.H    //---------------------------------------------------------------------------    #ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
   TButton *Button1;
   TMemo *Memo1;
   void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public:  // User declarations
   __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
/*生活是一種藝術,用心生活才能享受生活*/
發表人 - axsoft 於 2004/03/09 19:19:30
系統時間:2024-11-01 8:31:23
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!