I would like to search for every IP address in a curl output. Is there a quick way to do so? I know about regex_search from boost, but from what I read, it is targeted for files.
My actual non-working code:
#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;
}
Are you sure? From what I see here:
http://www.boost.org/doc/libs/1_45_0/libs/regex/doc/html/boost_regex/ref/regex_search.html
Am I missing something here?
Anyway, another option would be to filter curl’s output through grep.