开发者

php - socks proxy

For the past fifteen day I'm breaking my head to solve this issue. I have a PHP application which connects to a remote mysql server, but the application c开发者_如何转开发an't directly access the remote mysql server, it has to connect through a socks proxy. Please could anyone help me to solve this issue.

Thanks in advance.


I was looking to see if anyone else had done this yet, but I guess not. I made an interface to SOCKS4a for PHP. Here it is.

function fsocks4asockopen($proxyHostname, $proxyPort, $targetHostname, $targetPort)
{
    $sock = fsockopen($proxyHostname, $proxyPort);
    if($sock === false)
        return false;
    fwrite($sock, pack("CCnCCCCC", 0x04, 0x01, $targetPort, 0x00, 0x00, 0x00, 0x01, 0x00).$targetHostname.pack("C", 0x00));
    $response = fread($sock, 16);
    $values = unpack("xnull/Cret/nport/Nip", $response);
    if($values["ret"] == 0x5a) return $sock;
    else
    {
        fclose(sock);
        return false;
    }
}

Its not exactly a final product of any sort, but it will allow you to open a connection with a socks4a proxy from PHP and get back the same kind of socket you would with fsockopen


I think you'll need to set up port forwarding through your SOCKS proxy. With this you open a local port (e.g. on 3306) which forwards connections to a remote host and port (databasehost:3306) through a SOCKS proxy. You run this in the background and make PHP connect to localhost:3306 (which will then be forwarded/tunneled to databasehost:3306)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜