How find modem IP by usuing boost Asio

  asio, boost, c++, c++14, c++17

I am trying to get My modem IPV4 by using boost Asio and c++, For doing this I try this code :

 try {
        boost::asio::io_service netService;
        udp::resolver   resolver(netService);
        udp::resolver::query query(udp::v4(), "google.com", "");
        udp::resolver::iterator endpoints = resolver.resolve(query);
        udp::endpoint ep = *endpoints;
        udp::socket socket(netService);
        socket.connect(ep);
        boost::asio::ip::address addr = socket.local_endpoint().address();
        std::cout << "My IP according to google is: " << addr.to_string() << std::endl;

    } 
catch (std::exception& e)
    {
        std::cerr << "Could not deal with socket. Exception: " << e.what() << std::endl;

    }

but what this code show me is Interface IP means for example 192.168.1.100

But when I try it with IPV6, It works correctly.

now My question is why this happens and how can I get the correct IP?

Source: Windows Questions C++

LEAVE A COMMENT