Created
October 12, 2020 12:20
-
-
Save kasperhartwich/6a3e994fbb0f6c94359626d8a383429d to your computer and use it in GitHub Desktop.
Check to see if ip address comes from a Tor proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class TorProxy | |
{ | |
/** | |
* Is IP address a Tor proxy ip address. | |
* See https://lists.torproject.org/pipermail/tor-project/2020-March/002759.html | |
* | |
* @param $ip | |
* @return bool | |
*/ | |
public static function isTorIpAddress(string $ip): bool | |
{ | |
$host = implode('.', array_reverse(explode('.', $ip))) . '.dnsel.torproject.org'; | |
return !empty(dns_get_record($host)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment