Hier versie 0.1 van mijn proxy classe.
Hij houdt zelf een lijst met proxies bij en pikt hier steeds een random proxy uit, die zeker werkt. (test hem meteen)
Kan handig zijn als je jou scripts anoniem wilt laten surfen. (GPL)
[php]
<?php
define("CHECK_PROXY_HOST", "www.bastarddomain.nl"

define("CHECK_PROXY_URL", "http://" . CHECK_PROXY_HOST . $_SERVER['PHP_SELF'] . "?check"

define("CHECK_PROXY_STRING", "proxy=up"

define("CHECK_PROXY_SITE", "http://www.atomintersoft.com/products/alive-proxy/proxy-list/"

define("TABLE_PROXY", "proxy"

define("ONLINE", 1);
define("OFFLINE", 0);
define("TRACE", 0);
if (isset($_GET['check'])) {
die(CHECK_PROXY_STRING);
}
class Proxy {
var $ip;
var $port;
var $database = "<db>";
function Proxy() {
$mysql_user = "<user>";
$mysql_pass = "<pass>";
mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($this->database);
if (!$this->proxy_table_exists()) {
$this->proxy_create_table();
$this->proxy_update();
}
$this->proxy_pick($this->ip, $this->port);
}
function trace($str) {
if (TRACE) {
echo $str . "<br />\n";
flush();
}
return TRACE;
}
function proxy_create_table() {
$query = "CREATE TABLE " . TABLE_PROXY . " (id int auto_increment primary key, ip varchar(15), port mediumint unsigned, status tinyint unsigned)";
mysql_query($query) or die(mysql_error());
return true;
}
function proxy_table_exists() {
$result = mysql_list_tables($this->database);
while(list($table) = mysql_fetch_row($result))
if ($table == TABLE_PROXY)
return true;
return false;
}
function proxy_search() {
$fd = fopen(CHECK_PROXY_SITE, "r"

while (!feof($fd))
$content .= fgets($fd, 128);
fclose($fd);
$pattern = "'(\d{1,3}(?:\.\d{1,3}){3})

preg_match_all($pattern, $content, $matches);
$proxy = array();
for ($i = 0; $i < count($matches[0]); $i++) {
$proxy[$i]['ip'] = $matches[1][$i];
$proxy[$i]['port'] = $matches[2][$i];
}
$this->trace($i . " proxies were found"

return $proxy;
}
function proxy_save($array) {
$n = 0;
for ($i = 0; $i < count($array); $i++) {
if (!$this->proxy_in_list($array[$i]['ip'], $array[$i]['port']) && $this->proxy_check($array[$i]['ip'], $array[$i]['port'])) {
$this->proxy_add($array[$i]['ip'], $array[$i]['port']);
$n++;
}
}
$this->trace($n . " proxies were saved"

return $n;
}
function proxy_update() {
$p = proxy_search();
$n = proxy_save($p);
$this->trace($n . " proxies were stored"

return $n;
}
function proxy_in_list($ip, $port) {
$query = "SELECT id FROM " . TABLE_PROXY . " WHERE ip = '$ip' AND port = '$port'";
$result = mysql_query($query) or die(mysql_error());
list($id) = mysql_fetch_row($result);
return isset($id);
}
function proxy_count() {
$query = "SELECT COUNT(id) FROM " . TABLE_PROXY . " WHERE status = '" . ONLINE . "'";
$result = mysql_query($query) or die(mysql_error());
list($cnt) = mysql_fetch_row($result);
$this->trace("The list contains $cnt proxies"

}
function proxy_add($ip, $port) {
$query = "INSERT INTO " . TABLE_PROXY . " (id, ip, port) VALUES (null, '$ip', '$port')";
mysql_query($query) or die(mysql_error());
$this->trace($ip . ":" . $port . " was added to the list"

return mysql_insert_id();
}
function proxy_delete($ip, $port) {
$query = "DELETE FROM " . TABLE_PROXY . " WHERE ip = '$ip' AND port = '$port'";
mysql_query($query) or die(mysql_error());
$this->trace($ip . ":" . $port . " was deleted from the list"

return true;
}
function proxy_online($ip, $port) {
$query = "UPDATE " . TABLE_PROXY . " SET status = '" . ONLINE . "' WHERE ip = '$ip' AND port = '$port'";
mysql_query($query) or die(mysql_error());
$this->trace("The status of " . $ip . ":" . $port . " was changed to online"

return true;
}
function proxy_offline($ip, $port) {
$query = "UPDATE " . TABLE_PROXY . " SET status = '" . OFFLINE . "' WHERE ip = '$ip' AND port = '$port'";
mysql_query($query) or die(mysql_error());
$this->trace("The status of " . $ip . ":" . $port . " was changed to offline"

return true;
}
function proxy_check($proxy_ip, $proxy_port, $timeout=30) {
$fp = @fsockopen($proxy_ip, $proxy_port, $errno, $errstr, $timeout);
if (!$fp) {
return false;
} else {
$out = "GET " . CHECK_PROXY_URL . " HTTP/1.1\r\n";
$out .= "Host: " . CHECK_PROXY_HOST . "\r\n";
$out .= "Connection: Close\r\n";
$out .= "\r\n";
fwrite($fp, $out);
while (!feof($fp))
$in .= fgets($fp, 128);
fclose($fp);
if (ereg(CHECK_PROXY_STRING, $in)) {
$this->trace("The status of " . $proxy_ip . ":" . $proxy_port . " is online"

return true;
} else {
$this->proxy_offline($proxy_ip, $proxy_port);
$this->trace("The status of " . $proxy_ip . ":" . $proxy_port . " is offline"

return false;
}
}
}
function proxy_pick_any(&$ip, &$port) {
$query = "SELECT ip, port FROM " . TABLE_PROXY . " WHERE status = '" . ONLINE . "' ORDER BY RAND() LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
list($ip, $port) = mysql_fetch_row($result);
mysql_free_result($result);
$this->trace($ip . ":" . $port . " was picked from the list"

return $ip . ":" . $port;
}
function proxy_pick(&$ip, &$port) {
$this->proxy_pick_any($ip, $port);
if (!$this->proxy_check($ip, $port, 1))
$this->proxy_pick($ip, $port);
$this->trace($ip . ":" . $port . " was is online and ready to use"

//$this->ip = $ip;
//$this->port = $port;
return $ip . ":" . $port;
}
function proxy_show_all_online () {
$query = "SELECT ip, port FROM " . TABLE_PROXY . " WHERE status = '" . ONLINE . "'";
$result = mysql_query($query) or die(mysql_error());
while(list($ip, $port) = mysql_fetch_row($result)) {
echo $ip . ":" . $port . "<br />\n";
}
mysql_free_result($result);
}
}
$p = new Proxy();
echo $p->ip . ":" . $p->port;
?>
[/php]
This post was edited by Fox at 13 Jan 2005
Refuse to do what you don't want to do.
"http("http://www.bastarddomain.com/dev/ico/quote.php") . "\" target=\"_blank\">"