2017-05-24 74 views
0

我需要将所有TOR用户发送到自定义验证码。如何使用php从外部网页检索ip列表?

我怎么能检索与PHP这个IP列表:

Tor Bulk Exit List

这是我的PHP代码:

// Retrieve ip list 
    $deny_ips = file('https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=8.8.8.8'); 

    // Read user ip address 
    $ip = isset($_SERVER['REMOTE_ADDR']) ? trim($_SERVER['REMOTE_ADDR']) : ''; 

    // Search current IP in $deny_ips array and present Captcha 
    if ((array_search($ip, $deny_ips))!== FALSE) { 
    echo 'Captcha goes here!'; 
    exit; 
    } 

第一步 “获取IP地址列表” 是不正确的,我做的不知道如何检索它与PHP。

谢谢!

+0

它以哪种方式不正确?也许http(s)fopen包装在您的配置中被禁用? – ccKep

+0

我怀疑这是因为在第一步它不是一个文件,而是一个网页。我尝试了各种各样的东西,比如'数组'。不幸的是,我对php的理解仍然有限。 – Cell

+0

只要打开fopen包装,'file()'就可以读取URL。查看[php文档]中的信息(http://php.net/manual/en/function.file.php) – ccKep

回答

0

我有个想法。

$tor = file_get_contents('https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=8.8.8.8'); 
$array = explode('#', $tor); 
$ips = end($array); 
$ips_array = explode(PHP_EOL, $ips); 

If(in_array($ip, $ip_array)){ 
    echo 'ip found <br>'; 
}else{ 
    echo 'ip not found <br>'; 
} 

这可能会这样做。

+0

感谢您的帮助。我会尝试解决方案并在稍后报告结果。 – Cell

+0

您的解决方案与我的原始帖子以及我发布的其他解决方案一起工作。我接受了你的答案,因为你的支持非常快,你的答案与我在网上找到的所有其他解决方案不同。我也多了解或多或少了解你的代码,而我发布的另一个解决方案更具体,我不太了解代码。感谢您的回答。 – Cell

0

我找到了另一种方式来点击此处查看:Check if user uses TOR

因此,代码是这样的一个:

/** 
* detect if current user is using tor network 
* @return bool 
*/ 
function IsTorExitPoint(){ 
    if (gethostbyname(ReverseIPOctets($_SERVER['REMOTE_ADDR']).".".$_SERVER['SERVER_PORT'].".".ReverseIPOctets($_SERVER['SERVER_ADDR']).".ip-port.exitlist.torproject.org")=="127.0.0.2") { 
    return true; 
    } 
    else { 
    return false; 
    } 
} 

/** 
* reverse the ip 
* @param string $input 
* @return string 
*/ 
function ReverseIPOctets($inputip){ 
    $ipoc = explode(".",$inputip); 
    return $ipoc[3].".".$ipoc[2].".".$ipoc[1].".".$ipoc[0]; 
} 

/** 
* present custom captcha to user using tor network 
*/ 
if (IsTorExitPoint()) { 
    echo 'Captcha goes here!'; 
    exit; 
} 

不知道什么是根据性能问题做到这一点的最好办法。有没有办法用php来检查它?

我会在尝试所有可能的解决方案后报告更多信息。

谢谢。

相关问题