Answer the question
In order to leave comments, you need to log in
How to determine the proxy country, remove Chinese proxies and completely overwrite the file with the final result?
There is a php script for checking SOCKS5 proxy.
The script looks at the file: gotovo_vse_sellery_bezdybley.txt and checks if this file is empty or not. If the file is empty, then the script stops immediately.
If the file is not empty, then the script checks the proxy from the file for validity in the following way:
The script sends the string \x05\x01\x00 to each socks it managed to connect to, if the first 2 bytes of the response are \x05\x00\ then socks5 is considered valid
during the check - the script saves valid SOCKS5 to the file: socks5_valid.txt
<?php
$socks5_list = explode ("\n", str_replace ("\r", "", file_get_contents (dirname(__FILE__)."/gotovo_vse_sellery_bezdybley.txt")));
if (empty($socks5_list))
{
exit(1);
}
//скрипт получения двухсимвольного кода страны
/*
$country = geoip_country_code_by_name('www.example.com');
if ($country) {
echo 'Хост расположен в ' . $country;
*/
function _check_socks5 ($socks = array(), $filename)
{
foreach ($socks as $s)
{
list ($ip, $port) = explode (":", $s);
if ($socket = @fsockopen ($ip, $port, $errno, $errstr, 1))
{
$threads [$s] = $socket;
}
}
foreach ($threads as $s => $h)
{
fwrite ($h, "\x05\x01\x00");
}
foreach ($threads as $s => $h)
{
$r = fread ($h, 2);
if ((ord ($r [0]) == 5) && (ord ($r [1]) == 0))
{
file_put_contents ($filename, $s."\r\n", FILE_APPEND);
}
}
}
_check_socks5 ($socks5_list, dirname(__FILE__)."/socks5_valid.txt");
?>
$country = geoip_country_code_by_name('www.example.com');
if ($country) {
echo 'Хост расположен в ' . $country;
Answer the question
In order to leave comments, you need to log in
Does the irreconcilable fight against proxies continue? :P
<?php
$socks5_list = explode ("\n", str_replace ("\r", "", file_get_contents (dirname(__FILE__)."/gotovo_vse_sellery_bezdybley.txt")));
if (empty($socks5_list))
{
exit(1);
}
function _check_socks5 ($socks = array(), $filename)
{
foreach ($socks as $s)
{
list ($ip, $port) = explode (":", $s);
if (geoip_country_code_by_name($ip) == "CN") continue;
if ($socket = @fsockopen ($ip, $port, $errno, $errstr, 1))
{
$threads[$s] = $socket;
}
}
foreach ($threads as $s => $h)
{
fwrite ($h, "\x05\x01\x00");
}
foreach ($threads as $s => $h)
{
$r = fread ($h, 2);
if ((ord ($r [0]) == 5) && (ord ($r [1]) == 0))
{
file_put_contents ($filename, $s."\r\n");
}
}
}
_check_socks5 ($socks5_list, dirname(__FILE__)."/socks5_valid.txt");
?>
How can I make it not add new results after the old results, but completely overwrite the file: socks5_valid.txt with new results?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question