C++访问指定连接增加访问量

#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <ctime>

#ifdef linux
#include <unistd.h>
#endif // linux

#if defined(_WINDOWS) || defined(WIN32)
#include <windows.h>
#endif // _WIN32

using namespace std;
int main(int argc, char const *argv[])
{
    
    

#if defined(_WINDOWS) || defined(WIN32)
        system("chcp 65001");
        system("cls");
#endif // _WIN32

#ifdef linux
        system("clear");
#endif // linux

        ifstream file;
        file.open("./test.txt", ios::in);
        string buff, temp = "curl ", result;
        int order = 0;
        long long wheel = 1;
        vector<string> page;
        while (getline(file, buff))
        {
    
    

#if defined(_WINDOWS) || defined(WIN32)
                result = temp + buff + " >nul 2>nul";
#endif //  _WIN32

#ifdef linux
                result = temp + buff + " >/dev/null 2>/dev/null";
#endif // linux

                page.push_back(result);
        }
        file.close();
        int looptime = 0, onlytime = 0, randtask = 0;
        vector<int> randtasktable;
        cout << "正在准备执行第" << wheel << "轮" << endl;
        while (true)
        {
    
    
                randtasktable.clear();
                srand(time(NULL));
                while (true)
                {
    
    
                        randtask = rand() % page.size();
                        if (std::find(randtasktable.begin(), randtasktable.end(), randtask) == randtasktable.end())
                        {
    
    
                                randtasktable.push_back(randtask);
                        }
                        if (randtasktable.size() >= page.size() * 0.7)
                        {
    
    
                                break;
                        }
                }
                looptime = rand() % 3 + 3;
                cout << "正在执行第" << wheel << "轮" << endl;
                for (auto &i : randtasktable)
                {
    
    
                        onlytime = rand() % 3 + 1;
                        std::cout << "正在执行第" << ++order << "个" << std::endl;
                        system(page[i].c_str());

#if defined(_WINDOWS) || defined(WIN32)
                        Sleep(onlytime * 1000);
#endif //  _WIN32

#ifdef linux
                        sleep(onlytime);
#endif // linux
                }
                order = 0;

#if defined(_WINDOWS) || defined(WIN32)
                system("cls");
#endif //  _WIN32

#ifdef linux
                system("clear");
#endif // linux

                cout << "正在准备执行第" << ++wheel << "轮" << endl;

#if defined(_WINDOWS) || defined(WIN32)
                Sleep(1000 * 60 * looptime);
#endif //  _WIN32

#ifdef linux
                sleep(60 * looptime);
#endif // linux
        }

        return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44575789/article/details/108896157