开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from libhv/libhv
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (6)
标签 (13)
master
dev
kcptun
tfb
check_unicode
annotate
v1.3.3
v1.3.2
v1.3.1
v1.3.0
v1.2.6
v1.2.5
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.1.1
v1.1.0
v1.0.0
master
分支 (6)
标签 (13)
master
dev
kcptun
tfb
check_unicode
annotate
v1.3.3
v1.3.2
v1.3.1
v1.3.0
v1.2.6
v1.2.5
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.1.1
v1.1.0
v1.0.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (6)
标签 (13)
master
dev
kcptun
tfb
check_unicode
annotate
v1.3.3
v1.3.2
v1.3.1
v1.3.0
v1.2.6
v1.2.5
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.1.1
v1.1.0
v1.0.0
libhv
/
examples
/
nmap
/
main.cpp
libhv
/
examples
/
nmap
/
main.cpp
main.cpp 3.18 KB
一键复制 编辑 原始数据 按行查看 历史
ithewei 提交于 2022年08月01日 20:16 +08:00 . rm warning
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "nmap.h"
#include "hsocket.h"
#include "hthreadpool.h"
int host_discover_task(std::string segment, void* nmap) {
Nmap* hosts= (Nmap*)nmap;
return host_discover(segment.c_str(), hosts);
}
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("Usage: nmap segment\n");
printf("Examples: nmap 192.168.1.123\n");
printf(" nmap 192.168.1.x/24\n");
printf(" nmap 192.168.x.x/16\n");
return -1;
}
char* segment = argv[1];
char* split = strchr(segment, '/');
int n = 24;
if (split) {
*split = '0円';
n = atoi(split+1);
if (n != 24 && n != 16) {
return -2;
}
}
Nmap hosts;
char ip[INET_ADDRSTRLEN];
if (n == 24) {
host_discover(segment, &hosts);
}
else if (n == 16) {
Nmap segs;
int up_nsegs = segment_discover(segment, &segs);
if (up_nsegs == 0) return 0;
#if 1
for (auto& pair : segs) {
if (pair.second == 1) {
uint32_t addr = pair.first;
uint8_t* p = (uint8_t*)&addr;
// 0,255 reserved
for (int i = 1; i < 255; ++i) {
p[3] = i;
hosts[addr] = 0;
}
}
}
nmap_discover(&hosts);
#else
if (up_nsegs == 1) {
for (auto& pair : segs) {
if (pair.second == 1) {
inet_ntop(AF_INET, (void*)&pair.first, ip, sizeof(ip));
host_discover(ip, &hosts);
}
}
}
else {
// ThreadPool + host_discover
Nmap* hosts = new Nmap[up_nsegs];
// use ThreadPool
HThreadPool tp(4);
tp.start();
std::vector<std::future<int>> futures;
int i = 0;
for (auto& pair : segs) {
if (pair.second == 1) {
inet_ntop(AF_INET, (void*)&pair.first, ip, sizeof(ip));
auto future = tp.commit(host_discover_task, std::string(ip), &hosts[i++]);
futures.push_back(std::move(future));
}
}
// wait all task done
int nhosts = 0;
for (auto& future : futures) {
nhosts += future.get();
}
// filter up hosts
std::vector<uint32_t> up_hosts;
for (int i = 0; i < up_nsegs; ++i) {
Nmap& nmap = hosts[i];
for (auto& host : nmap) {
if (host.second == 1) {
up_hosts.push_back(host.first);
}
}
}
delete[] hosts;
}
#endif
}
// filter up hosts
std::vector<uint32_t> up_hosts;
for (auto& pair : hosts) {
if (pair.second == 1) {
up_hosts.push_back(pair.first);
}
}
// print up hosts
printf("Up hosts %lu:\n", (unsigned long)up_hosts.size());
for (auto& host : up_hosts) {
inet_ntop(AF_INET, (void*)&host, ip, sizeof(ip));
printf("%s\n", ip);
}
return 0;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

🔥 比libevent/libuv/asio更易用的国产网络库,用来开发 TCP/UDP/SSL/HTTP/WebSocket/MQTT 客户端/服务端
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cppprojects/libhv.git
git@gitee.com:cppprojects/libhv.git
cppprojects
libhv
libhv
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /