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