DWORD Err;
PFIXED_INFO pFixedInfo;
DWORD FixedInfoSize = 0;
PIP_ADAPTER_INFO pAdapterInfo, pAdapt;
DWORD AdapterInfoSize;
PIP_ADDR_STRING pAddrStr;
Memo1->Lines->Clear();
// Get the main IP configuration information for this machine using a FIXED_INFO structure
if ((Err = GetNetworkParams(NULL, &FixedInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
Memo1->Lines->Add("GetNetworkParams sizing failed with error"+AnsiString(Err));
return;
}
}
// Allocate memory from sizing information
if ((pFixedInfo = (PFIXED_INFO) GlobalAlloc(GPTR, FixedInfoSize)) == NULL)
{
Memo1->Lines->Add("Memory allocation error");
return;
}
if ((Err = GetNetworkParams(pFixedInfo, &FixedInfoSize)) == 0)
{
Memo1->Lines->Add("Host Name :"+AnsiString(pFixedInfo->HostName));
pAddrStr = pFixedInfo->DnsServerList.Next;
}
else
{
Memo1->Lines->Add("GetNetworkParams failed with error "+Err);
return;
}
//
// Enumerate all of the adapter specific information using the IP_ADAPTER_INFO structure.
// Note: IP_ADAPTER_INFO contains a linked list of adapter entries.
//
AdapterInfoSize = 0;
if ((Err = GetAdaptersInfo(NULL, &AdapterInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
Memo1->Lines->Add("GetAdaptersInfo sizing failed with error "+Err);
return;
}
}
// Allocate memory from sizing information
if ((pAdapterInfo = (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) == NULL)
{
Memo1->Lines->Add("Memory allocation error/n");
return;
}
// Get actual adapter information
if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0)
{
Memo1->Lines->Add("GetAdaptersInfo failed with error %d/n"+Err);
return;
}
pAdapt = pAdapterInfo;
while (pAdapt)
{
int i=1;
Memo1->Lines->Add("Physical Address : ");
String str="";
for (int i=0; i <6; i++)
{
if (i>0)
str=str+"-";
str=str+IntToHex(int(pAdapt->Address[i]),2);
}
Memo1->Lines->Add(str);
pAddrStr = &(pAdapt->IpAddressList);
while(pAddrStr)
{
Memo1->Lines->Add("IP Address : "+AnsiString(pAddrStr->IpAddress.String));
pAddrStr = pAddrStr->Next;
}
while(pAddrStr)
{
Memo1->Lines->Add(AnsiString(pAddrStr->IpAddress.String));
pAddrStr = pAddrStr->Next;
}
pAdapt = pAdapt->Next;
}
get ip,mac
最新推荐文章于 2024-04-26 21:22:53 发布