用asio写端口扫描器?缪缪数行而已

本文分享了如何利用asio库轻松编写一个端口扫描器。通过简洁的代码示例,展示在C++中进行TCP端口扫描的简单方法。
摘要由CSDN通过智能技术生成

用asio写网络,简直是种享受啊,贴出来交流交流,代码直接拷到新工程的main.cpp里编译就行了

#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>

#include <boost/asio.hpp>
using namespace boost::asio;

#include <boost/system/error_code.hpp>
using boost::system::error_code;

#include <boost/bind.hpp>
using boost::bind;

#include <iostream>
using std::cout;
using std::endl;

#include <cstring>
using std::strcmp;

#include <cstdlib>
using std::atoi;


typedef boost::shared_ptr<ip::tcp::socket> socket_sp;
void conn_handler(socket_sp sock, ip::tcp::endpoint ep, const error_code& ec)
{
    if (!ec)
    {
        cout << ep.address().to_string() << ":" << ep.port() << endl;
    }

    if (ec != error::operation_aborted)
    {
        sock->close();
    }
}

void scan_ip(const char* start, const char* end, unsigned short port)
{
    unsigned long s = ntohl(ine
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值