Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /** Cloudflare Resolver **
- */
- interface ICFlareResolver {
- public function resolve_cf($url);
- public function isValidIp($ip);
- public function isValidUrl($url);
- public function isCloudFlare($host);
- }
- class CFlareResolver implements ICFlareResolver {
- private $_addr_alloc = array(
- '199.27.128.0/21',
- '173.245.48.0/20',
- '103.21.244.0/22',
- '103.22.200.0/22',
- '103.31.4.0/22',
- '141.101.64.0/18',
- '108.162.192.0/18',
- '190.93.240.0/20',
- '188.114.96.0/20',
- '197.234.240.0/22',
- '198.41.128.0/17',
- '162.158.0.0/15',
- '104.16.0.0/12',
- '172.64.0.0/13'
- );
- private $_subd_alloc = array(
- 'mail',
- 'direct',
- 'direct-connect',
- 'cpanel',
- 'ftp',
- 'forum',
- 'blog',
- 'test',
- 'dev',
- 'webmail',
- 'record',
- 'homepage',
- 'testing',
- 'secure',
- 'server',
- 'news',
- 'images',
- 'irc',
- 'groups',
- 'cp',
- 'info',
- 'games',
- 'music',
- 'portal',
- 'ssl',
- 'dns',
- 'help',
- 'host',
- 'www',
- 'help',
- 'images',
- 'news',
- '1'
- );
- public function resolve_cf($url) {
- if(!$this->isValidUrl($url)) {
- $url = "http://{$url}";
- }
- if($this->isCloudFlare($url)) {
- $host = parse_url($url)['host'];
- if(strstr($host, 'www.')) {
- $host = explode('www.', $host)[1];
- }
- foreach($this->_subd_alloc as $subdomain) {
- $host_pre_ = "{$subdomain}.{$host}";
- $host_ip = $this->getIp($host_pre_);
- if($this->isValidIp($host_ip)) {
- if($this->isCloudFlare($host_ip))
- echo "{$host_pre_}:::{$host_ip}:::Cloudflare" . (isset($ARGV[0])?"\r\n":"<br>\r\n";
- else {
- echo "{$host_pre_}:::{$host_ip}:::DirectIP" . (isset($ARGV[0])?"\r\n":"<br>\r\n";
- }
- }
- }
- }
- }
- public function isValidIp($ip) {
- return filter_var($ip, FILTER_VALIDATE_IP) ? true : false;
- }
- public function isValidUrl($url) {
- return filter_var($url, FILTER_VALIDATE_URL) ? true : false;
- }
- public function isCloudFlare($host) {
- if($this->isValidIp($host)) {
- foreach($this->_addr_alloc as $addr_alloc) {
- if($this->cidr_match($host, $addr_alloc)) {
- return true;
- }
- }
- return false;
- }
- elseif($this->isValidUrl($host)) {
- $headers = implode("\n", get_headers($host));
- $headers = explode("cloudflare", $headers);
- return count($headers)>1 ? true : false;
- }
- }
- private function getIp($host)
- {
- return gethostbyname($host);
- }
- private function cidr_match($ip, $range) {
- list ($subnet, $bits) = explode('/', $range);
- $ip = ip2long($ip);
- $subnet = ip2long($subnet);
- $mask = -1 << (32 - $bits);
- $subnet &= $mask; # nb: in case the supplied subnet wasn't correctly aligned
- return ($ip & $mask) == $subnet;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment