Code:
<h3>sunjester's proxy checker</h3>
<p>This checker requires your proxies to be in the format of IP:PORT</p>
<p>This checker will determine if a proxy is online and what type of proxy it is.</p>
<form method="post">
<p><textarea name="proxies" cols="80" rows="20" placeholder="paste your proxies here"></textarea></p>
<p>
<b>Output</b><br/>
<!--input type="radio" name="output" id="json_out" value="json" /> <label for="json_out">JSON output</label-->
<input type="radio" name="output" id="raw_out" value="raw" checked /><label for="raw_out">Raw</label>
</p>
<p><button type="submit">Check proxies</button></p>
</form>
<?php
if($_POST)
{
$checker = new SJProxyChecker($_POST['proxies']);
echo $checker->check();
}
class SJProxyChecker
{
private $ip;
private $port;
private $proxies;
private $proxy_types = [
"CURLPROXY_SOCKS5",
"CURLPROXY_HTTP",
"CURLPROXY_HTTPS",
"CURLPROXY_HTTP_1_0",
"CURLPROXY_SOCKS4",
"CURLPROXY_SOCKS4A"
];
private $result = "<table border=1>";
function __construct($proxylist)
{
$this->proxies = explode("\n", $proxylist);
}
function check()
{
foreach($this->proxies as $proxy)
{
foreach($this->proxy_types as $type)
{
$proxy_info = explode(":", $proxy);
if($this->isOnline($proxy_info[0], $proxy_info[1]))
{
$r = $this->makeReq($proxy, $type);
if($r == $proxy_info[0])
{
$this->result .= "<tr><td>".$proxy."</td><td>".$type."</td></tr>";
break;
}
}
}
}
$this->result .= "</table>";
return $this->result;
}
function isOnline($ip, $port)
{
if(fsockopen($ip, $port, $errno, $errstr, 30))
{
return true;
} else {
return false;
}
}
function makeReq($proxy, $type)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.ipify.org");
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, $type);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
?>