2015-06-18 61 views
0

我已经安装了Tor中继和Nginx,并在我的Linux服务器上创建了我的.onion。PHP:Tor检查不工作

在的torrc HiddenServicePort 80 127.0.0.1:8747

在nginx的默认:listen 8747

我修改TorDNSExitList的PHP梨Net_DNS使用Net_DNS2。当我回声出$ip, $myip, $myport我得到:

ip = 127.0.0.1 
my ip = 127.0.0.1 
port = 8747 

因此它是捡的IP地址为本地计算机,而不是Tor出口节点的IP地址。是否有另一个为什么要测试页面是否通过Tor网络访问?

(我也尝试this suggestion

回答

0

解决的办法是检查127.0.0.1 IP地址,看到的torrc指向127.0.0.1。这在通过.onion路径访问网站时起作用。但是完整的检查仍然需要完成,因为网站可以通过完整的URL访问,例如, http:// [IP地址]:[端口] - 使用“普通”或Tor浏览器。

<?php include("Net/DNS2.php"); 
// torel_check ($ip, $port, $destip) queries the Tor DNS Exit List server. 
// The result of the query is one of the following: 
// -1 : DNS lookup failed to get a response, or other error occurred. 
// 0 : $ip does not appear to be a Tor exit. 
// 1 : $ip is a known Tor exit for the provided destination IP/port. 
function revaddr ($ip) { 
    list($a, $b, $c, $d) = split("[.]", $ip); 
    return("${d}.${c}.${b}.${a}"); 
} 

function torel_qh ($ip, $port, $destip) { 
    $rsrcip = revaddr ($ip); 
    $rdstip = revaddr ($destip); 
    return("${rsrcip}.${port}.${rdstip}.ip-port.exitlist.torproject.org"); 
} 

function torel_check ($ip, $port, $destip) { 
    try{ 
     if($ip == "127.0.0.1") { 
      //TX: Access via .onion path 
      // is Tor exit 
      return (1); 
     } 
     //TX: Access web site directly 
     $ndr = new Net_DNS2_Resolver(); 
     $qh = torel_qh($ip, $port, $destip); 

     // uncomment these two lines to query the server directly... 
     //$ns = "exitlist-ns.torproject.org"; 
     //$ndr->nameservers(array($ns)); 

     // tune DNS params accordingly. this is just my preference. 
     $ndr->retrans = 2; 
     $ndr->retry = 3; 
     $ndr->usevc = 0; 

     // perform DNS query 
     // TX: Old Net_DNS check $ndr->search($qh) 
     if (! $pkt = $ndr->query($qh)) { 
      if (strcmp($ndr->errorstring, "NXDOMAIN") == 0) { 
       // response but no answer. does not appear to be Tor exit. 
       return (0); 
      } 
      // search failed: no response or other problem... 
      return(-1); 
     } 
     if (! isset($pkt->answer[0])) { 
      // response but no answer section. does not appear to be Tor exit. 
      // (this should only happen when authority sections are provided without answer) 
      return(0); 
     } 
     // is Tor exit 
     return(1); 
    } catch(Net_DNS2_Exception $e) { 
     return (-1); 
    } 
} 

// get client request parameters from Apache or equiv server: 
$ip = $myip = $myport = 0; 
if (isset ($_SERVER["REMOTE_ADDR"])) { $ip = $_SERVER["REMOTE_ADDR"]; } 
if (isset ($_SERVER["SERVER_ADDR"])) { $myip = $_SERVER["SERVER_ADDR"]; } 
if (isset ($_SERVER["SERVER_PORT"])) { $myport = $_SERVER["SERVER_PORT"]; } 

$istor = torel_check($ip, $myport, $myip); 

TX:我下面的功能改变是我的意见