PHP:Tor检查不工作

PHP:Tor检查不工作,php,nginx,ip,tor,Php,Nginx,Ip,Tor,我已经安装了Tor中继和Nginx,并在Linux服务器上创建了我的.onion 在torrcHiddenServicePort 80 127.0.0.1:8747中 在nginx的默认设置中:listen8747 我已经修改了PHP的Pear Net_DNS以使用Net_DNS2。当我回显$ip、$myip、$myport时,我得到: ip = 127.0.0.1 my ip = 127.0.0.1 port = 8747 因此,它选择IP地址作为本地机器,而不是Tor出口节点的IP地址。是

我已经安装了Tor中继和Nginx,并在Linux服务器上创建了我的.onion

在torrc
HiddenServicePort 80 127.0.0.1:8747中

在nginx的默认设置中:
listen8747

我已经修改了PHP的Pear Net_DNS以使用Net_DNS2。当我回显
$ip、$myip、$myport
时,我得到:

ip = 127.0.0.1
my ip = 127.0.0.1
port = 8747
因此,它选择IP地址作为本地机器,而不是Tor出口节点的IP地址。是否还有其他原因需要测试页面是否通过Tor网络访问


(我也尝试过)

解决方案是检查127.0.0.1IP地址,看到torrc指向127.0.0.1。这在通过.onion路径访问网站时有效。但是仍然需要进行全面检查,因为可以通过完整URL访问网站,例如http://[IP地址]:[Port]——使用“普通”或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);