자기 자신(컴퓨터)의 IP 어드레스는 다음과 같은 방법으로 얻을 수 있습니다.


처음에는 IPv6 주소, 두 번째는 IPv4 주소가 나옵니다.


std::cout << "1" << std::endl; boost::asio::io_service io_service; boost::asio::ip::tcp::resolver resolver(io_service); boost::asio::ip::tcp::resolver::query query(boost::asio::ip::host_name(), ""); boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query); boost::asio::ip::tcp::resolver::iterator end; // End marker. while (iter != end) { boost::asio::ip::tcp::endpoint ep = *iter++; std::cout << ep << std::endl; } { std::cout << "2" << std::endl; boost::asio::ip::tcp::resolver resolver(io_service);

boost::asio::ip::tcp::resolver::query query(boost::asio::ip::host_name(),""); boost::asio::ip::tcp::resolver::iterator it=resolver.resolve(query); while(it!=boost::asio::ip::tcp::resolver::iterator()) { boost::asio::ip::address addr=(it++)->endpoint().address(); if(addr.is_v6()) { std::cout<<"ipv6 address: "; } else std::cout<<"ipv4 address: "; std::cout<<addr.to_string()<<std::endl; } }





by 흥배 2013.07.04 08:00