得到适配器所有地址 DHCP IP..........

//#include<Winsock2.h>
//#include<Iphlpapi.h>
//#include<Ndis.h>

PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = NULL;
DWORD dwRetVal = 0;

pAdapterInfo= (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) );
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);

// Make an initial call to GetAdaptersInfo to get
// the necessary size into the ulOutBufLen variable
if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
  free(pAdapterInfo);
  pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
}

if ((dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
  pAdapter = pAdapterInfo;
  while (pAdapter) {
    printf("/tAdapter Name: /t%s/n", pAdapter->AdapterName);
    printf("/tAdapter Desc: /t%s/n", pAdapter->Description);
    printf("/tAdapter Addr: /t%ld/n", pAdapter->Address);
    printf("/tIP Address: /t%s/n", pAdapter->IpAddressList.IpAddress.String);
    printf("/tIP Mask: /t%s/n", pAdapter->IpAddressList.IpMask.String);

    printf("/tGateway: /t%s/n", pAdapter->GatewayList.IpAddress.String);
    printf("/t***/n");
    if (pAdapter->DhcpEnabled) {
      printf("/tDHCP Enabled: Yes/n");
      printf("/t/tDHCP Server: /t%s/n", pAdapter->DhcpServer.IpAddress.String);
      printf("/tLease Obtained: %ld/n", pAdapter->LeaseObtained);
    }
    else
      printf("/tDHCP Enabled: No/n");
   
    if (pAdapter->HaveWins) {
      printf("/tHave Wins: Yes/n");
      printf("/t/tPrimary Wins Server: /t%s/n", pAdapter->PrimaryWinsServer.IpAddress.String);
      printf("/t/tSecondary Wins Server: /t%s/n", pAdapter->SecondaryWinsServer.IpAddress.String);
    }
    else
      printf("/tHave Wins: No/n");
    pAdapter = pAdapter->Next;
  }
}
else {
  printf("Call to GetAdaptersInfo failed./n");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值