ipconfig vs2010 C+++



 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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值