1. 程式人生 > >boost.asio學習-----reslover 域名解析

boost.asio學習-----reslover 域名解析

address main 學習 sin www. != code pre urn

將域名解析為ip地址並輸出:

 1 #include "stdafx.h"
 2 #include "boost/asio.hpp"
 3 #include <boost/lexical_cast.hpp>
 4 
 5 using namespace std;
 6 using namespace boost::asio;
 7 
 8 int _tmain(int argc, _TCHAR* argv[])
 9 {
10     boost::asio::io_service ios;
11     //創建resolver對象
12     ip::tcp::resolver slv(ios);
13 //創建query對象 14 ip::tcp::resolver::query qry("www.google.com", boost::lexical_cast<string>(0)); 15 //使用resolve叠代端點 16 ip::tcp::resolver::iterator it = slv.resolve(qry); 17 ip::tcp::resolver::iterator end; 18 vector<string> ip; 19 for (; it != end; it++) 20 { 21
ip.push_back((*it).endpoint().address().to_string()); 22 } 23 24 for (int i = 0; i < ip.size(); i++) 25 { 26 cout << ip[i] << endl; 27 } 28 getchar(); 29 return 0; 30 }

boost.asio學習-----reslover 域名解析