LPCTSTR GetNodeTypeName(UINT NodeType)
{
switch (NodeType) {
case 1: return _T("Broadcast");
case 2: return _T("Peer To Peer");
case 4: return _T("Mixed");
case 8: return _T("Hybrid");
default : return _T("unknown");
}
}
LPCTSTR GetInterfaceTypeName(UINT InterfaceType)
{
switch (InterfaceType) {
case MIB_IF_TYPE_OTHER: return _T("Other Type Of Adapter");
case MIB_IF_TYPE_ETHERNET: return _T("Ethernet Adapter");
case MIB_IF_TYPE_TOKENRING: return _T("Token Ring Adapter");
case MIB_IF_TYPE_FDDI: return _T("FDDI Adapter");
case MIB_IF_TYPE_PPP: return _T("PPP Adapter");
case MIB_IF_TYPE_LOOPBACK: return _T("Loopback Adapter");
case MIB_IF_TYPE_SLIP: return _T("SLIP Adapter");
default: return _T("unknown");
}
}
char* ShowInfo(BOOL bAll)
{
char szBuf[4096]="";
PIP_ADAPTER_INFO pAdapterInfo = NULL;//?句要
PIP_ADAPTER_INFO pAdapter = NULL;//?句要
ULONG adaptOutBufLen;//?句要
PFIXED_INFO pFixedInfo;
ULONG netOutBufLen;
PIP_ADDR_STRING pIPAddr = NULL;
DWORD ErrRet = 0;
/* assign memory for call to GetNetworkParams */
pFixedInfo = (FIXED_INFO *) GlobalAlloc( GPTR, sizeof( FIXED_INFO ) );
netOutBufLen = sizeof(FIXED_INFO);
/* assign memory for call to GetAdapterInfo */
pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof( IP_ADAPTER_INFO ) );//?句要
adaptOutBufLen = sizeof(IP_ADAPTER_INFO);//?句要
/* set required buffer size */
if(GetNetworkParams(pFixedInfo, &netOutBufLen) == ERROR_BUFFER_OVERFLOW)
{
GlobalFree(pFixedInfo);
pFixedInfo = (FIXED_INFO *) GlobalAlloc(GPTR, netOutBufLen);
}
/* set required buffer size */
if (GetAdaptersInfo( pAdapterInfo, &adaptOutBufLen) == ERROR_BUFFER_OVERFLOW) //?句要
{
free(pAdapterInfo);//?句要
pAdapterInfo = (IP_ADAPTER_INFO *) malloc (adaptOutBufLen);//?句要
}
if ((ErrRet = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen)) != NO_ERROR)
{
sprintf(szBuf,"GetAdaptersInfo failed : ");
DoFormatMessage(ErrRet);
return "";
}
if ((ErrRet = GetNetworkParams(pFixedInfo, &netOutBufLen)) != NO_ERROR)
{
sprintf(szBuf,"GetNetworkParams failed : ");
DoFormatMessage(ErrRet);
return "";
}
pAdapter = pAdapterInfo;
if (bAll)
{
sprintf(szBuf,"%s\tHost Name . . . . . . . . . . . . : %s\n",szBuf, pFixedInfo->HostName);
sprintf(szBuf,"%s\tPrimary DNS Suffix. . . . . . . . : \n",szBuf);
sprintf(szBuf,"%s\tNode Type . . . . . . . . . . . . : %s\n",szBuf, GetNodeTypeName(pFixedInfo->NodeType));
if (pFixedInfo->EnableRouting)
sprintf(szBuf,"%s\tIP Routing Enabled. . . . . . . . : Yes\n",szBuf);
else
sprintf(szBuf,"%s\tIP Routing Enabled. . . . . . . . : No\n",szBuf);
if (pAdapter->HaveWins)
sprintf(szBuf,"%s\tWINS Proxy enabled. . . . . . . . : Yes\n",szBuf);
else
sprintf(szBuf,"%s\tWINS Proxy enabled. . . . . . . . : No\n",szBuf);
sprintf(szBuf,"%s\tDNS Suffix Search List. . . . . . : %s\n",szBuf, pFixedInfo->DomainName);
}
while (pAdapter)
{
sprintf(szBuf,"%s\n%s ...... : \n\n",szBuf, GetInterfaceTypeName(pAdapter->Type));
/* check if the adapter is connected to the media */
if (_tcscmp(pAdapter->IpAddressList.IpAddress.String,"0.0.0.0") == 0)
{
sprintf(szBuf,"%s\tMedia State . . . . . . . . . . . : Media disconnected\n",szBuf);
pAdapter = pAdapter->Next;
continue;
}
sprintf(szBuf,"%s\tConnection-specific DNS Suffix. . : %s\n",szBuf, pFixedInfo->DomainName);
if (bAll)
{
sprintf(szBuf,"%s\tDescription . . . . . . . . . . . : %s\n",szBuf, pAdapter->Description);
sprintf(szBuf,"%s\tPhysical Address. . . . . . . . . : %s\n",szBuf, PrintMacAddr(pAdapter->Address));
if (pAdapter->DhcpEnabled)
sprintf(szBuf,"%s\tDHCP Enabled. . . . . . . . . . . : Yes\n",szBuf);
else
sprintf(szBuf,"%s\tDHCP Enabled. . . . . . . . . . . : No\n",szBuf);
sprintf(szBuf,"%s\tAutoconfiguration Enabled . . . . : \n",szBuf);
}
sprintf(szBuf,"%s\tIP Address. . . . . . . . . . . . : %s\n",szBuf, pAdapter->IpAddressList.IpAddress.String);//?句要
sprintf(szBuf,"%s\tSubnet Mask . . . . . . . . . . . : %s\n",szBuf, pAdapter->IpAddressList.IpMask.String);
sprintf(szBuf,"%s\tDefault Gateway . . . . . . . . . : %s\n",szBuf, pAdapter->GatewayList.IpAddress.String);
if (bAll)
{
if (pAdapter->DhcpEnabled)
sprintf(szBuf,"%s\tDHCP Server . . . . . . . . . . . : %s\n",szBuf, pAdapter->DhcpServer.IpAddress.String);
sprintf(szBuf,"%s\tDNS Servers . . . . . . . . . . . : ",szBuf);
sprintf(szBuf,"%s%s\n",szBuf, pFixedInfo->DnsServerList.IpAddress.String);
pIPAddr = pFixedInfo -> DnsServerList.Next;
while (pIPAddr)
{
sprintf(szBuf,"%s\t\t\t\t\t %s\n",szBuf, pIPAddr ->IpAddress.String );
pIPAddr = pIPAddr ->Next;
}
if (pAdapter->HaveWins)
{
sprintf(szBuf,"%s\tPrimary WINS Server . . . . . . . : %s\n",szBuf, pAdapter->PrimaryWinsServer.IpAddress.String);
sprintf(szBuf,"%s\tSecondard WINS Server . . . . . . : %s\n",szBuf, pAdapter->SecondaryWinsServer.IpAddress.String);
}
//if (pAdapter->DhcpEnabled)
//{
// //sprintf(szBuf,"%s\tLease Obtained. . . . . . . . . . : %s",szBuf, _tasctime(localtime(&pAdapter->LeaseObtained)));
// //sprintf(szBuf,"%s\tLease Expires . . . . . . . . . . : %s",szBuf, _tasctime(localtime(&pAdapter->LeaseExpires)));
// sprintf(szBuf,"\tLease Obtained. . . . . . . . . . : %s", _tasctime(localtime(&pAdapter->LeaseObtained)));
// sprintf(szBuf,"\tLease Expires . . . . . . . . . . : %s", asctime(localtime(&pAdapter->LeaseExpires)));
//}
}
sprintf(szBuf,"%s\n",szBuf);
pAdapter = pAdapter->Next;
}
return szBuf;
}