How to get the IPv4 address on windows in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main() {
    // ipconfig:  IPv4 Address. . . . . . . . . . . : 101.11.1.111
    char IPv4Line[] = "IPv4 Address. . . . . . . . . . . :";  
         
    system("ipconfig > ip.txt");
 
    FILE *IPFile = fopen("ip.txt", "r");
    char line[80];
    while (fgets(line, sizeof(line), IPFile))  {
            if (strstr(line, IPv4Line) != NULL) {
                strcpy(line, line + 39);
                puts(line);
                fclose(IPFile);
            }
    }
     
    return 0;
}
 
 
 
 
/*
run:
 
101.11.1.111
 
*/

 



answered Apr 8, 2021 by avibootz
edited Apr 8, 2021 by avibootz

Related questions

1 answer 189 views
1 answer 151 views
151 views asked Apr 18, 2021 by avibootz
1 answer 257 views
1 answer 156 views
1 answer 201 views
...