Help! Socks proxy wrapper class doesn't work
Posted: Tue Dec 14, 2004 4:59 am
Hello all, i'm trying to use a class found on phpclasses.org no author support.
It's a tcp connection wrapper that use socks 5 proxy to connect to a target server.
I read the rfc1928 for socks proxy and it should work but i dont' receive response from the socks when i request a the connetion to the target server.
This is a simple test code
The socks used is an anonymous one found on the net.
In this line 7 i receive this warning
Warning: unpack(): Type C: not enough input, need 1, have 0
because
in the function connect of the class
at this line 13 $buf["recv"] is empty since fread($this->socket, 1024) doesn't read anything.
Why?
Anyone can help me please?
P.S. Sorry for my english, i hope you can understand what is the problem, thanks
It's a tcp connection wrapper that use socks 5 proxy to connect to a target server.
I read the rfc1928 for socks proxy and it should work but i dont' receive response from the socks when i request a the connetion to the target server.
This is a simple test code
Code: Select all
$server_name = "www.google.com";
$server_port = 80;
$socks = new socks5("212.244.158.169", 29992);
if ($socks) {
$socks->connect($server_name, $server_port);
if ($socks->connected)
echo "Connection OK";
else
echo "Connection KO";
}
else
{
echo "No socks connection";
}In this line 7 i receive this warning
Warning: unpack(): Type C: not enough input, need 1, have 0
because
in the function connect of the class
Code: Select all
function connect($host, $port) {
if ($this->socket) {
if (ip2long($host) == -1) {
$buf["send"] = pack("C5", 0x05, 0x01, 0x00, 0x03, strlen($host)).$host.pack("n", $port);
} else {
$buf["send"] = pack("C4Nn", 0x05, 0x01, 0x00, 0x01, ip2long(gethostbyname($host)), $port);
}
fwrite($this->socket, $buf["send"]);
$buf["recv"] = "";
while ($buffer = fread($this->socket, 1024)) {
$buf["recv"] .= $buffer;
}
$responce = unpack("Cversion/Cresult/Creg/Ctype/Lip/Sport", $buf["recv"]);
if ($responce["version"] == 0x05 and $responce["result"] == 0x00) {
$this->connected = true;
return true;
}
}
$this->connected = false;
return false;
}Why?
Anyone can help me please?
P.S. Sorry for my english, i hope you can understand what is the problem, thanks