您的位置:首页 > 其它

boost::asio 查询网址ip和端口

2014-07-31 00:56 351 查看
#include "stdafx.h"
#include <string>
#include <boost/asio.hpp>
using namespace std;
using namespace boost::asio;
int _tmain(int argc, _TCHAR* argv[])
{
io_service my_io_service;
ip::tcp::resolver resolver(my_io_service);//create a resolver in order to resolve the name of host and query 
                                     //the name of sercice and host,then converte them to one or more endpoints
ip::tcp::resolver::query query("www.baidu.com", "http");//create a query
ip::tcp::resolver::iterator iter = resolver.resolve(query);
ip::tcp::resolver::iterator end; // end marker
while (iter != end)
{
ip::tcp::endpoint endpoint = *iter++;
std::cout << endpoint << std::endl; //display ip and port.the style of display is like 10.0.0.1:80
}

return 0;
}

this picture display the result

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: