Skip to content

Instantly share code, notes, and snippets.

@kasperhartwich
Created October 12, 2020 12:20
Show Gist options
  • Save kasperhartwich/6a3e994fbb0f6c94359626d8a383429d to your computer and use it in GitHub Desktop.
Save kasperhartwich/6a3e994fbb0f6c94359626d8a383429d to your computer and use it in GitHub Desktop.
Check to see if ip address comes from a Tor proxy
<?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