#include <stdio.h> #include <windows.h> #include <stdlib.h> #include <malloc.h> #include "Iphlpapi.h" #pragma comment(lib,"IPHLPAPI.LIB") int main() { PIP_ADAPTER_INFO pAdapterInfo; PIP_ADAPTER_INFO pAdapter = NULL; DWORD dwRetVal = 0; pAdapterInfo = (IP_ADAPTER_INFO*)malloc(sizeof(PIP_ADAPTER_INFO)); ULONG ulOutBufLen = sizeof(PIP_ADAPTER_INFO); 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("Adapter Name:\t%s\n",pAdapter->AdapterName); printf("Adapter Desc:\t%s\n",pAdapter->Description); printf("Adapter Addr:\t%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x", pAdapter->Address[0],pAdapter->Address[1],pAdapter->Address[2], pAdapter->Address[3],pAdapter->Address[4],pAdapter->Address[5]); printf("IP Address:\t%s\n",pAdapter->IpAddressList.IpAddress.String); printf("IP Mask:\t%s\n",pAdapter->IpAddressList.IpMask.String); printf("GateWay:\t%s\n",pAdapter->GatewayList.IpAddress.String); printf("**********************\n"); if(pAdapter->DhcpEnabled) { printf("DHCP Enabled : YES\n"); printf("\tDHCP Server:\t%s\n",pAdapter->DhcpServer.IpAddress.String); printf("Lease Obtained:%ld\n",pAdapter->LeaseObtained); } else { printf("DHCP Enabled : NO \n"); } if(pAdapter->HaveWins) { printf("Have Wins : YES"); printf("\tPrimary Wins Server :\t%s\n",pAdapter->PrimaryWinsServer.IpAddress.String); printf("\tSecondary Wins Server : \t%s\n",pAdapter->SecondaryWinsServer.IpAddress.String); } else { printf("Have Wins :NO\n"); } pAdapter = pAdapter->Next; } } else { printf("Call to GetAdaptersInfo failed\n"); } return 0; }
..