程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> VC >> VC++ >> 得到網卡信息源代碼

得到網卡信息源代碼

編輯:VC++

#include
#include
#include
#include

void main(void) {

DWORD Err;

PIP_ADAPTER_INFO pAdapterInfo, pAdapt;
DWORD AdapterInfoSize;
PIP_ADDR_STRING pAddrStr;

//
// Get the main IP configuration information for this machine using a FIXED_INFO structure
//

AdapterInfoSize = 0;
if ((Err = GetAdaptersInfo(NULL, &AdapterInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
printf("GetAdaptersInfo sizing failed with error %d\n", Err);
return;
}
}

// Allocate memory from sizing information
if ((pAdapterInfo = (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) == NULL)
{
printf("Memory allocation error\n");
return;
}

// Get actual adapter information
if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0)
{
printf("GetAdaptersInfo failed with error %d\n", Err);
return;
}

pAdapt = pAdapterInfo;

while (pAdapt)
{
switch (pAdapt->Type)
{
case MIB_IF_TYPE_ETHERNET:
printf("\nEthernet adapter ");
break;
case MIB_IF_TYPE_TOKENRING:
printf("\nToken Ring adapter ");
break;
case MIB_IF_TYPE_FDDI:
printf("\nFDDI adapter ");
break;
case MIB_IF_TYPE_PPP:
printf("\nPPP adapter ");
break;
case MIB_IF_TYPE_LOOPBACK:
printf("\nLoopback adapter ");
break;
case MIB_IF_TYPE_SLIP:
printf("\nSlip adapter ");
break;
case MIB_IF_TYPE_OTHER:
default:
printf("\nOther adapter ");
}
printf("%s:\n\n", pAdapt->AdapterName);

printf("\tDescription . . . . . . . . : %s\n", pAdapt->Description);

printf("\tPhysical Address. . . . . . : ");
for (UINT i=0; iAddressLength; i++)
{
if (i == (pAdapt->AddressLength - 1))
printf("%.2X\n",(int)pAdapt->Address[i]);
else
printf("%.2X-",(int)pAdapt->Address[i]);
}

printf("\tDHCP Enabled. . . . . . . . : %s\n", (pAdapt->DhcpEnabled ? "yes" : "no"));

pAddrStr = &(pAdapt->IpAddressList);
while(pAddrStr)
{
printf("\tIP Address. . . . . . . . . : %s\n", pAddrStr->IpAddress.String);
printf("\tSubnet Mask . . . . . . . . : %s\n", pAddrStr->IpMask.String);
pAddrStr = pAddrStr->Next;
}

printf("\tDefault Gateway . . . . . . : %s\n", pAdapt->GatewayList.IpAddress.String);
pAddrStr = pAdapt->GatewayList.Next;
while(pAddrStr)
{
printf("%52s\n", pAddrStr->IpAddress.String);
pAddrStr = pAddrStr->Next;
}

printf("\tDHCP Server . . . . . . . . : %s\n", pAdapt->DhcpServer.IpAddress.String);
printf("\tPrimary WINS Server . . . . : %s\n", pAdapt->PrimaryWinsServer.IpAddress.String);
printf("\tSecondary WINS Server . . . : %s\n", pAdapt->SecondaryWinsServer.IpAddress.String);

struct tm *newtime;

// Display coordinated universal time - GMT
newtime = gmtime(&pAdapt->LeaseObtained);
printf( "\tLease Obtained. . . . . . . : %s", asctime( newtime ) );

newtime = gmtime(&pAdapt->LeaseExpires);
printf( "\tLease Expires . . . . . . . : %s", asctime( newtime ) );

pAdapt = pAdapt->Next;
}
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved