How to get the IPv6 address on windows in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
  
int main() {
    // ipconfig: IPv6 Address. . . . . . . . . . . : 2021:a83:85c3:0000:0000:1e2e:0180:7555
    char IPv6Line[] = "IPv6 Address. . . . . . . . . . . :";  
          
    system("ipconfig > ip.txt");
  
    FILE *IPFile = fopen("ip.txt", "r");
    char line[80];
	char line1 = 1;
    while (fgets(line, sizeof(line), IPFile))  {
			if (strstr(line, IPv6Line) != NULL && line1 == 1) {
				line1++;
				continue;
			}
            if (strstr(line, IPv6Line) != NULL) {
                strcpy(line, line + 39);
                puts(line);
                fclose(IPFile);
            }
    }
      
    return 0;
}
  
  
  
  
/*
run:
  
2021:a83:85c3:0000:0000:1e2e:0180:7555
  
*/

 



answered Apr 18, 2021 by avibootz

Related questions

1 answer 156 views
1 answer 233 views
233 views asked Apr 8, 2021 by avibootz
1 answer 189 views
3 answers 375 views
1 answer 234 views
...