Загрузка...

Proxy checker C++ (дельта версия)

Тема в разделе C/C++ создана пользователем Rahmat_inactive2177540 26 фев 2020. 365 просмотров

Загрузка...
  1. Rahmat_inactive2177540
    Rahmat_inactive2177540 Автор темы 26 фев 2020 Заблокирован(а) 53 6 апр 2019
    Код

    #include <bits/stdc++.h>
    #include <tchar.h>
    #include <wininet.h>
    using namespace std;

    int n;
    char* p[2];
    int port;
    char inname[15]= "proxy.txt";
    char outname[15]= "valid.txt";

    char* unconstchar(const char* s) {
    int i;
    char* res;
    for (i = 0; s[i] != '\0'; i++) {
    res[i] = s[i];
    }
    res[i] = '\0';
    return res;
    }

    int main()
    {
    ifstream fin(inname);
    ofstream fout(outname);
    cin>>n;
    const char* s[n];
    char *p[n];
    HINTERNET hopen;
    HINTERNET hconnect;
    HINTERNET hquery;
    for (int i=0; i<n; ++i){
    fin>>p[i];
    s[i] = p[i];
    port = stoi(strtok(p[i], ":"));
    hopen = InternetOpenA(_T("Mozilla 4.0"), INTERNET_OPEN_TYPE_PROXY, s[i], 0, 0);
    if (hopen!=NULL){
    hconnect = InternetConnectA(hopen, _T("google.com"), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
    if (hconnect!=NULL){
    hquery = HttpOpenRequestA(hconnect, _T("GET"), _T("index,html"), 0, 0, 0, INTERNET_FLAG_KEEP_CONNECTION, 0);
    if (hquery!=NULL){
    bool hsend = HttpSendRequestA(hquery, 0, 0, 0, 0);
    if (hsend==true){
    fout<<s[i];
    }
    }
    }
    }
    CloseHandle(hopen);
    CloseHandle(hconnect);
    CloseHandle(hquery);

    }
    return 0;
    }
    Я заметил ошибку в коде, помогите исправить
    Код
    port = stoi(strtok(p[i], ":"));
    В этом фрагменте программа должна разделять строку на лексемы, превращать в число, которое будет портом, но она преобразует самое первое число, которое не является портом. Можно как-нибудь сделать, чтобы часть после ":" преобразовывалась в число?
     
  2. Fender_inactive2697143
    Отпиши в ЛС
     
  3. RaysMorgan
    Надо смотреть что возвращает
    Код
    strtok(p[i], ":")
    и дальше уже смотреть, что не так
     
  4. Rahmat_inactive2177540
    Rahmat_inactive2177540 Автор темы 26 фев 2020 Заблокирован(а) 53 6 апр 2019
    RaysMorgan, если p="1.0.0.1:80", то возвращает 1, а мне бы хотелось 80, то есть после ":" преобразовывать в int
     
  5. Fender_inactive2697143
    RaysMorgan, указатель на последнюю найденную лексему в строке, в противном случае вернёт пустой указатель. С ТС сейчас в ЛС свяжемся, помогу ему
    Rahmat_inactive2177540, посимвольно сканируй
     
  6. Fender_inactive2697143
    Связались с ТС, сделал ему следующий код:
    Код
    #include <cstdio>
    #include <stdlib.h>

    int main()
    {
    char str[] = "89.12.45:80";
    char strNumber[] = { 0 };

    unsigned int findIndex = 0;

    for (unsigned int i = 0; i < sizeof(str); i++)
    {
    if (findIndex == 0)
    {
    if (str[i] == ':')
    findIndex = i + 1;
    }
    else
    strNumber[i - findIndex] = strNumber[i + 1];
    }

    unsigned int readyNumber = std::atoi(strNumber);

    printf("%d\n", readyNumber);

    system("pause");
    return 0;
    }
    Вывод: 80 как число
     
Top