How to get the IPv6 address on windows in C++

1 Answer

0 votes
#include <iostream>
#include <fstream>
 
int main() {
    std::string line;
    std::ifstream IPFile;
     // ipconfig: IPv6 Address. . . . . . . . . . . : 2021:a83:85c3:0000:0000:1e2e:0180:7555
    char IPv6Line[] = "IPv6 Address. . . . . . . . . . . :";  
	char line1 = 1;
         
    system("ipconfig > ip.txt");
 
    IPFile.open("ip.txt"); 
    if (IPFile.is_open()) {
        while(!IPFile.eof()) {
            getline(IPFile, line);
			if (line.find(IPv6Line, 0) != std::string::npos && line1 == 1) {
				line1 = 2;
				continue;
			}
            if (line.find(IPv6Line, 0) != std::string::npos) {
                line.erase(0, 39);
                std::cout << line << "\n";
                IPFile.close();
            }
        }
    }
    return 0;
}
 
 
 
/*
run:
 
2021:a83:85c3:0000:0000:1e2e:0180:7555
 
*/

 



answered Apr 18, 2021 by avibootz

Related questions

1 answer 151 views
151 views asked Apr 18, 2021 by avibootz
1 answer 188 views
1 answer 232 views
232 views asked Apr 8, 2021 by avibootz
3 answers 375 views
1 answer 106 views
1 answer 234 views
...