1. Go to this page and download the library: Download infostars/socks-react library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$loop = React\EventLoop\Factory::create();
// start a new SOCKS proxy server
$server = new Clue\React\Socks\Server($loop);
// listen on localhost:1080
$socket = new React\Socket\Server('127.0.0.1:1080', $loop);
$server->listen($socket);
$loop->run();
$connector = new React\Socket\Connector($loop);
$client = new Client('127.0.0.1:1080', $connector);
$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'dns' => false
));
// now create an SSL encrypted connection (notice the $ssl instead of $tcp)
$connector->connect('tls://www.google.com:443')->then(function (ConnectionInterface $stream) {
// proceed with just the plain text data
// everything is encrypted/decrypted automatically
echo 'connected to SSL encrypted www.google.com';
$stream->write("GET / HTTP/1.0\r\n\r\n");
// ...
});
// all three forms are equivalent
$client = new Client('127.0.0.1', $connector);
$client = new Client('socks://127.0.0.1', $connector);
$client = new Client('socks5://127.0.0.1', $connector);
$client = new Client('socks4://127.0.0.1', $connector);
// set up Connector which uses Google's public DNS (8.8.8.8)
$connector = new React\Socket\Connector($loop, array(
'tcp' => $client,
'dns' => '8.8.8.8'
));
// throws InvalidArgumentException
new Client('socks4://user:[email protected]', $connector);
// https via the proxy chain "MiddlemanSocksServer -> TargetSocksServer -> TargetHost"
// please note how the client uses TargetSocksServer (not MiddlemanSocksServer!),
// which in turn then uses MiddlemanSocksServer.
// this creates a TCP/IP connection to MiddlemanSocksServer, which then connects
// to TargetSocksServer, which then connects to the TargetHost
$middle = new Client('127.0.0.1:1080', new Connector($loop));
$target = new Client('example.com:1080', $middle);
$connector = new React\Socket\Connector($loop, array(
'tcp' => $target,
'dns' => false
));
$connector->connect('tls://www.google.com:443')->then(function ($stream) {
// …
});
$client = new Client('sockss://127.0.0.1:1080', new Connector($loop));
$client = new Client('socks4s://127.0.0.1:1080', new Connector($loop));
$client = new Client('sockss://user:[email protected]:1080', new Connector($loop));
$client = new Client('socks+unix:///tmp/proxy.sock', new Connector($loop));
$client = new Client('socks4+unix:///tmp/proxy.sock', new Connector($loop));
$client = new Client('socks+unix://user:pass@/tmp/proxy.sock', new Connector($loop));
$loop = React\EventLoop\Factory::create();
$server = new Clue\React\Socks\Server($loop);
// listen on localhost:$port
$socket = new React\Socket\Server($port, $loop);
$server->listen($socket);
$loop->run();
$server = new Clue\React\Socks\Server($loop, null, function ($user, $pass, $remote) {
// $remote is a full URI à la socks://user:[email protected]:1234
// or sockss://user:[email protected]:1234 for SOCKS over TLS
// or may be null when remote is unknown (SOCKS over Unix Domain Sockets)
// useful for logging or extracting parts, such as the remote IP
$ip = parse_url($remote, PHP_URL_HOST);
return ($user === 'root' && $pass === 'secret' && $ip === '127.0.0.1');
});
$server = new Clue\React\Socks\Server($loop, null, function ($user, $pass) use ($db) {
// pseudo-code: query database for given authentication details
return $db->query(
'SELECT 1 FROM users WHERE name = ? AND password = ?',
array($username, $password)
)->then(function (QueryResult $result) {
// ensure we find exactly one match in the database
return count($result->resultRows) === 1;
});
});
$loop = React\EventLoop\Factory::create();
// set next SOCKS server example.com:1080 as target
$connector = new React\Socket\Connector($loop);
$client = new Clue\React\Socks\Client('user:[email protected]:1080', $connector);
// start a new server which forwards all connections to the other SOCKS server
$server = new Clue\React\Socks\Server($loop, $client);
// listen on localhost:1080
$socket = new React\Socket\Server('127.0.0.1:1080', $loop);
$server->listen($socket);
$loop->run();
$loop = React\EventLoop\Factory::create();
$server = new Clue\React\Socks\Server($loop);
// listen on tls://127.0.0.1:1080 with the given server certificate
$socket = new React\Socket\Server('tls://127.0.0.1:1080', $loop, array(
'tls' => array(
'local_cert' => __DIR__ . '/localhost.pem',
)
));
$server->listen($socket);
$loop->run();
$loop = React\EventLoop\Factory::create();
$server = new Clue\React\Socks\Server($loop);
// listen on /tmp/proxy.sock
$socket = new React\Socket\Server('unix:///tmp/proxy.sock', $loop);
$server->listen($socket);
$loop->run();
$client = new Client('127.0.0.1:1080', $connector);
$client = new Client('socks+unix:///tmp/proxy.sock', $connector);
$client = new Client('127.0.0.1:9050', $connector);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.