ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
C/C++

Proxy checking

Submitted by pizzaman66621 at 21-06-2023, 04:41 AM


Proxy checking
3.953 Views
pizzaman66621's Avatar'
pizzaman66621
Offline
#1
Hi Im working on a C++ checker. Well as of right now Im just testing certain parts out like multi threading and some other shit but I was wondering how would someone check if a proxy is working or not. I do know that sometimes some proxies are presumed as dead but then 5 minutes later they are working. I just dont know how to make a simple proxy checker? Do I like use some type of web api or like setup a socket? 

Thanks
0
Reply
pizzaman66621's Avatar'
pizzaman66621
Offline
#2
Ok so I was thinking about managing proxies through response time and came up with this code. Here it is...
Things to note: 
   - You can change the response time
   - I used boost::asio(Through VCPKG) 
   - Program slows down at some points 

#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

// Function to check if the proxy has a high response time
bool isHighResponseTime(const std::string& proxyAddress)
{
try
{
boost::asio::io_context ioContext;
boost::asio::ip::tcp::resolver resolver(ioContext);
boost::asio::ip::tcp::resolver::query query(proxyAddress, "http");
boost::asio::ip::tcp::resolver::iterator endpointIterator = resolver.resolve(query);

boost::asio::ip::tcp::socket socket(ioContext);
boost::asio::connect(socket, endpointIterator);

// Send a request and measure the time taken to get a response
std::string request = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
boost::posix_time::ptime startTime = boost::posix_time::microsec_clock::local_time();
boost::asio::write(socket, boost::asio::buffer(request));

// Read and discard the response
boost::asio::streambuf response;
boost::asio::read_until(socket, response, "\r\n\r\n");

// Calculate the duration in milliseconds
boost::posix_time::ptime endTime = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_duration responseTime = endTime - startTime;
int duration = responseTime.total_milliseconds();

// Check if the response time is considered high (e.g., more than 500 milliseconds)
if (duration > 500)
{
return true;
}
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what() << std::endl;
}

return false;
}

int main()
{
std::string proxyAddress;

std::cout << "Enter the proxy address: ";
std::getline(std::cin, proxyAddress);

if (isHighResponseTime(proxyAddress))
{
std::cout << "Proxy has a high response time.\n";
}
else
{
std::cout << "Proxy has a normal response time.\n";
}

return 0;
}
0
Reply
SwiftProxyioAce's Avatar'
SwiftProxyioAce
Offline
#3
lets check
0
Reply
drywizard's Avatar'
drywizard
Offline
#4
21-06-2023, 04:41 AM pizzaman66621 Wrote:
Hi Im working on a C++ checker. Well as of right now Im just testing certain parts out like multi threading and some other shit but I was wondering how would someone check if a proxy is working or not. I do know that sometimes some proxies are presumed as dead but then 5 minutes later they are working. I just dont know how to make a simple proxy checker? Do I like use some type of web api or like setup a socket? 

Thanks
what is a proxy without a proxy
DRYWIZARD
0
Reply



Users browsing this thread: 1 Guest(s)