首页 > 其他 > 详细

boost.asio学习-----reslover 域名解析

时间:2018-07-24 17:03:56      阅读:263      评论:0      收藏:0      [点我收藏+]

将域名解析为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 域名解析

原文:https://www.cnblogs.com/tyche116/p/9360407.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!