Can I detect Tor Browser inside the browser itself, via Javascript I suppose?

前端 未结 5 984
别那么骄傲
别那么骄傲 2021-01-02 15:05

I\'d like to disable some features of a web app I\'m building, if the browser is Tor Browser. Can I inside the browser itself (client side, not server side) find out if the

5条回答
  •  抹茶落季
    2021-01-02 16:03

    The "official" way to detect tor is to check the user's IP address and see if it's a tor exit node. Tor runs TorDNSEL for this purpose.

    Here's a PHP implementation of a TorDNSEL lookup from a tutorial by Irongeek

    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;
        } 
    }
    
    function ReverseIPOctets($inputip){
        $ipoc = explode(".",$inputip);
        return $ipoc[3].".".$ipoc[2].".".$ipoc[1].".".$ipoc[0];
    }
    

    If you're not using PHP, you should still be able to adapt this relatively easily.

    Another method of detecting Tor is to have a script download the list of Tor exit nodes every half hour or so, then check each user's IP address against that list. This may be less reliable, though, as not all exit nodes are published. There's a list you can use, and instructions, available at dan.me.uk.

    EDIT: Since you updated your question, the second option (a list you host locally) is going to be preferable.

提交回复
热议问题