Я хотел бы найти каждый IP-адрес в выводе curl. Есть ли быстрый способ сделать это? Я знаю о regex_search от boost, но из того, что я прочитал, он предназначен для файлов.
Мой действительный нерабочий код:
#include <iostream>
#include <curl/curl.h>
#include <boost/regex.hpp>
using namespace std;
boost::regex expression("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
boost::smatch what; // "match" specialized for std::string of char
boost::match_flag_type flags = boost::match_default;
string buffer = "hey";
int writer(char *data, size_t size, size_t nmemb, string *buffer){
int result = 0;
if(buffer != NULL) {
buffer -> append(data, size * nmemb);
result = size * nmemb;
}
return result;
}
int main(int argc, char *argv[]) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.xroxy.com/proxylist.php");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0); /* Don't follow anything else than the particular url requested*/
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer); /* Function Pointer "writer" manages the required buffer size */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer ); /* Data Pointer &buffer stores downloaded web content */
curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
if (boost::regex_search(buffer.begin(), buffer.end(), what, expression, flags) ) {
cout << "found: " << what << endl;
}
return 0;
}