1 #include "stdio.h" 2 #include "windows.h" 3 4 void GetHostWLAN_IPv4_AND_MAC(char IPv4[], char MAC[]); //获取WLAN下的IPv4和MAC地址,局域网网关IPv4地址(基于win10中文版编写) 5 6 int main() 7 { 8 char IPv4[16] = { 0 }; 9 char MAC[18] = { 0 }; 10 11 GetHostWLAN_IPv4_AND_MAC(IPv4,MAC); 12 13 printf("%s %d ", IPv4, strlen(IPv4)); 14 printf("%s %d ", MAC, strlen(MAC)); 15 return 0; 16 } 17 18 void GetHostWLAN_IPv4_AND_MAC(char IPv4[],char MAC[]) 19 { 20 memset(IPv4, 0, sizeof(IPv4)); 21 memset(MAC, 0, sizeof(MAC)); 22 system("ipconfig/all > E:\ipconfig.txt"); 23 FILE *fp = fopen("E:\ipconfig.txt", "r"); 24 if (!fp) 25 { 26 printf("failed to open file!"); 27 exit(-1); 28 } 29 char strInfo[128] = { 0 }; 30 bool find_wlan = false; 31 bool find_mac = false; 32 bool find_ipv4 = false; 33 34 int i, pos; 35 while (fgets(strInfo, 128, fp) != NULL) 36 { 37 if (strstr(strInfo, "WLAN") != NULL) 38 find_wlan = true; 39 40 if (find_wlan) 41 { 42 if (strstr(strInfo, "物理地址") != NULL) //获取MAC地址 43 { 44 pos = 16; 45 for (i = strlen(strInfo);; i--) 46 { 47 if (strInfo[i - 2] != '