note 47892 deleted from function.gethostbynamel by bjori

From: Date: Sat, 30 Sep 2006 00:12:19 +0000
Subject: note 47892 deleted from function.gethostbynamel by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117869@lists.php.net to get a copy of this message
Note Submitter: php at silisoftware dot com ---- This is a replacement for gethostbynamel(), for *nix only, which uses the "host" program to lookup hostnames. Most people won't need this, but I had a temporary server problem where all the PHP DNS lookup functions were failing, so this works as a direct replacement: function SafeGetHostByNameL($hostname) { if (false) { // put conditional check here to use normal gethostbynamel() return gethostbynamel($hostname); } elseif (ereg('[0-9]{1,3}(\.[0-9]{1,3}){3}', $hostname)) { return array($hostname); } else { $response = trim(host $hostname); if (preg_match_all('/([a-z0-9\.\-]* is an alias for ([a-z0-9\.\-]*)\.['." \r\n".']+)*[a-z0-9\.\-]* has address ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/', trim($response), $matches, PREG_PATTERN_ORDER)) { return $matches[3]; } elseif (eregi('^Host '.$hostname.' not found', $response, $matches)) { return false; } } return false; }

« previous php.notes (#117869) next »