diff --git a/README.md b/README.md index d9253fd..49c8dd0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# php-whois (UNMAINTAINED) +# php-whois PHP class to retrieve WHOIS information. diff --git a/examples/usage-example.php b/examples/usage-example.php index ec9b4a7..b4284cc 100644 --- a/examples/usage-example.php +++ b/examples/usage-example.php @@ -3,6 +3,7 @@ include '../src/Phois/Whois/Whois.php'; $sld = 'reg.ru'; +//$sld = 'com.sk'; // Not found. The Domain cannot be registered $domain = new Phois\Whois\Whois($sld); diff --git a/src/Phois/Whois/Whois.php b/src/Phois/Whois/Whois.php index 739de3c..ace66c9 100644 --- a/src/Phois/Whois/Whois.php +++ b/src/Phois/Whois/Whois.php @@ -15,7 +15,7 @@ class Whois /** * @param string $domain full domain name (without trailing dot) */ - public function __construct($domain) + public function __construct($domain, $proxy = false) { $this->domain = $domain; // check $domain syntax and split full domain name on subdomain and TLDs @@ -25,6 +25,9 @@ public function __construct($domain) ) { $this->subDomain = $matches[1]; $this->TLDs = $matches[2]; + if ($proxy) { + $this->proxy = $proxy; + } } else throw new \InvalidArgumentException("Invalid $domain syntax"); // setup whois servers array from json file @@ -39,7 +42,7 @@ public function info() // If TLDs have been found if ($whois_server != '') { - // if whois server serve replay over HTTP protocol instead of WHOIS protocol + // if whois server serve reply over HTTP protocol instead of WHOIS protocol if (preg_match("/^https?:\/\//i", $whois_server)) { // curl session to get whois reposnse @@ -52,6 +55,11 @@ public function info() curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + if ($proxy) { + curl_setopt($ch, CURLOPT_PROXY, $proxy['ip']); + curl_setopt($ch, CURLOPT_PROXYPORT, $proxy['port']); + } + $data = curl_exec($ch); if (curl_error($ch)) { @@ -63,8 +71,12 @@ public function info() } else { + // check whois server exist + if (gethostbyname($whois_server) == $whois_server) { + return "Whois server not exist error!"; + } // Getting whois information - $fp = fsockopen($whois_server, 43); + $fp = fsockopen($whois_server, 43, $errno, $errstr, 20); if (!$fp) { return "Connection error!"; } @@ -154,32 +166,45 @@ public function getSubDomain() return $this->subDomain; } - public function isAvailable() - { - $whois_string = $this->info(); - $not_found_string = ''; - if (isset($this->servers[$this->TLDs][1])) { - $not_found_string = $this->servers[$this->TLDs][1]; - } - - $whois_string2 = @preg_replace('/' . $this->domain . '/', '', $whois_string); - $whois_string = @preg_replace("/\s+/", ' ', $whois_string); - - $array = explode (":", $not_found_string); - if ($array[0] == "MAXCHARS") { - if (strlen($whois_string2) <= $array[1]) { - return true; - } else { - return false; - } - } else { - if (preg_match("/" . $not_found_string . "/i", $whois_string)) { - return true; - } else { - return false; - } - } - } + public function isAvailable() + { + $whois_string = $this->info(); + $not_found_string = ''; + if (isset($this->servers[$this->TLDs][1])) { + $not_found_strings = array_slice($this->servers[$this->TLDs], 1); + } + + $whois_string2 = @preg_replace('/' . $this->domain . '/', '', $whois_string); + $whois_string = @preg_replace("/\s+/", ' ', $whois_string); + + $return = true; + + if (is_array($not_found_strings)) { + foreach ($not_found_strings as $not_found_string) { + $array = explode (":", $not_found_string); + if ($array[0] == "MAXCHARS") { + if (strlen($whois_string2) <= $array[1]) { + $return &= true; + } else { + $return &= false; + } + } else if ($array[0] == "NEGATION") { + if (preg_match("/" . $array[1] . "/i", $whois_string)) { + $return &= false; + } else { + $return &= true; + } + } else { + if (preg_match("/" . $not_found_string . "/i", $whois_string)) { + $return &= true; + } else { + $return &= false; + } + } + } + } + return $return; + } public function isValid() { @@ -198,4 +223,9 @@ public function isValid() return false; } + + public function isServerDefined() { + return isset($this->servers[$this->TLDs]); + } + } diff --git a/src/Phois/Whois/whois.servers.json b/src/Phois/Whois/whois.servers.json index f270d3a..456a100 100644 --- a/src/Phois/Whois/whois.servers.json +++ b/src/Phois/Whois/whois.servers.json @@ -32,16 +32,16 @@ "NOT FOUND" ], "ac.jp": [ - "whois.nic.ad.jp", + "whois.jprs.jp", "No match!!" ], "ac.ke": [ "whois.kenic.or.ke", - "Not Registered" + "No Object Found" ], "ac.kr": [ "whois.nic.or.kr", - "is not registered" + "domain was not found" ], "ac.nz": [ "whois.srs.net.nz", @@ -55,10 +55,6 @@ "whois.ja.net", "Sorry - no" ], - "ac.za": [ - "whois.co.za", - "No information available" - ], "academy": [ "whois.donuts.co", "Domain not found" @@ -68,7 +64,7 @@ "Domain not found." ], "actor": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "ad": [ @@ -120,7 +116,7 @@ "No information available" ], "airforce": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "allfinanz": [ @@ -131,10 +127,6 @@ "whois-alsace.nic.fr", "Requested Domain cannot be found" ], - "alt.za": [ - "whois.co.za", - "No information available" - ], "am": [ "whois.nic.am", "No match" @@ -216,7 +208,7 @@ "No Data Found" ], "auction": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "audio": [ @@ -577,7 +569,7 @@ ], "co.ac": [ "whois.nic.ac", - "Available" + "not registered" ], "co.at": [ "whois.nic.at", @@ -592,7 +584,7 @@ "NOT FOUND" ], "co.jp": [ - "whois.nic.ad.jp", + "whois.jprs.jp", "No match!!" ], "co.ke": [ @@ -601,7 +593,7 @@ ], "co.kr": [ "whois.nic.or.kr", - "is not registered" + "domain was not found" ], "co.nz": [ "whois.srs.net.nz", @@ -617,7 +609,7 @@ ], "co.uk": [ "whois.nic.uk", - "No match" + "No match for" ], "co.ve": [ "whois.nic.ve", @@ -737,7 +729,7 @@ ], "com.ua": [ "whois.net.ua", - "No entries found" + "no object found" ], "com.ve": [ "whois.nic.ve", @@ -764,7 +756,7 @@ "Domain not found" ], "consulting": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "contractors": [ @@ -832,7 +824,7 @@ "Domain not found." ], "dance": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "dating": [ @@ -868,7 +860,7 @@ "Domain not found." ], "democrat": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "dental": [ @@ -925,7 +917,7 @@ ], "dn.ua": [ "whois.net.ua", - "No entries found" + "No match record found" ], "docs": [ "domain-registry-whois.l.google.com", @@ -963,6 +955,10 @@ "whois.nic.br", "No match for" ], + "eco.br": [ + "whois.nic.br", + "No match for" + ], "edu": [ "whois.internic.net", "No match for" @@ -971,10 +967,6 @@ "whois.aunic.net", "No Data Found" ], - "edu.cn": [ - "whois.cnnic.net.cn", - "no matching record" - ], "edu.gr": [ "http:\/\/grwhois.ics.forth.gr:800\/plainwhois\/plainWhois?domainName=", "not exist" @@ -1019,10 +1011,6 @@ "whois.metu.edu.tr", "No match found" ], - "edu.za": [ - "whois.co.za", - "No information available" - ], "education": [ "whois.donuts.co", "Domain not found" @@ -1232,7 +1220,7 @@ "Domain not found." ], "forsale": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "fot.br": [ @@ -1268,7 +1256,7 @@ "Domain not found." ], "futbol": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found" ], "g12.br": [ @@ -1384,16 +1372,16 @@ "% no matching objects found" ], "go.id": [ - "whois.idnic.net.id", - "Not found" + "whois.pandi.or.id", + "DOMAIN NOT FOUND" ], "go.jp": [ - "whois.nic.ad.jp", + "whois.jprs.jp", "No match!!" ], "go.kr": [ "whois.nic.or.kr", - "is not registered" + "domain was not found" ], "go.th": [ "whois.thnic.net", @@ -1459,10 +1447,6 @@ "whois.nic.mm", "No domains matched" ], - "gov.mx": [ - "whois.nic.mx", - "Object_Not_Found" - ], "gov.my": [ "whois.mynic.net.my", "does not exist" @@ -1475,10 +1459,6 @@ "whois.metu.edu.tr", "No match found" ], - "gov.za": [ - "whois.co.za", - "No information available" - ], "gq": [ "whois.dominio.gq", "Invalid query or domain name not known" @@ -1556,7 +1536,7 @@ "Domain not found." ], "haus": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "hb.cn": [ @@ -1688,7 +1668,7 @@ "Domain not found." ], "immobilien": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "in": [ @@ -1840,7 +1820,7 @@ "No match found" ], "kaufen": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "kddi": [ @@ -1857,7 +1837,7 @@ ], "kh.ua": [ "whois.net.ua", - "No entries found" + "No match record found" ], "ki": [ "whois.nic.ki", @@ -1865,7 +1845,7 @@ ], "kiev.ua": [ "whois.net.ua", - "No entries found" + "no object found" ], "kim": [ "whois.afilias.net", @@ -1953,7 +1933,7 @@ ], "lg.ua": [ "whois.net.ua", - "No entries found" + "No match record found" ], "lgbt": [ "whois.afilias.net", @@ -2029,7 +2009,7 @@ ], "lviv.ua": [ "whois.net.ua", - "No entries found" + "no object found" ], "ly": [ "whois.nic.ly", @@ -2148,21 +2128,13 @@ "DOMINIO NO REGISTRADO" ], "mil.id": [ - "whois.idnic.net.id", - "Not found" + "whois.pandi.or.id", + "DOMAIN NOT FOUND" ], "mil.pl": [ "whois.dns.pl", "No information available" ], - "mil.tr": [ - "whois.metu.edu.tr", - "No match found" - ], - "mil.za": [ - "whois.co.za", - "No information available" - ], "mini": [ "whois.ksregistry.net", "not found..." @@ -2192,7 +2164,7 @@ "NOT FOUND" ], "moda": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "monash": [ @@ -2268,12 +2240,12 @@ "No entries found" ], "ne.jp": [ - "whois.nic.ad.jp", + "whois.jprs.jp", "No match!!" ], "ne.kr": [ "whois.nic.or.kr", - "is not registered" + "domain was not found" ], "net": [ "whois.crsnic.net", @@ -2365,7 +2337,7 @@ ], "net.ua": [ "whois.net.ua", - "No entries found" + "no object found" ], "net.uk": [ "whois.nic.uk", @@ -2375,10 +2347,6 @@ "whois.nic.ve", "No match for" ], - "net.za": [ - "whois.co.za", - "No information available" - ], "network": [ "whois.donuts.co", "Domain not found." @@ -2407,10 +2375,6 @@ "http:\/\/www2.dot.ph\/WhoIs.asp?Domain=", "is still available" ], - "ngo.za": [ - "whois.co.za", - "No information available" - ], "nico": [ "whois.nic.nico", "DOMAIN NOT FOUND" @@ -2433,7 +2397,7 @@ ], "nm.kr": [ "whois.nic.or.kr", - "is not registered" + "domain was not found" ], "no": [ "whois.norid.no", @@ -2459,10 +2423,6 @@ "whois.rotld.ro", "No entries found" ], - "nom.za": [ - "whois.co.za", - "No information available" - ], "nra": [ "whois.afilias-srs.net", "NOT FOUND" @@ -2524,12 +2484,12 @@ "nothing found" ], "or.jp": [ - "whois.nic.ad.jp", + "whois.jprs.jp", "No match!!" ], "or.kr": [ "whois.nic.or.kr", - "is not registered" + "domain was not found" ], "or.th": [ "whois.thnic.net", @@ -2808,7 +2768,7 @@ "no match" ], "pub": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "pw": [ @@ -2837,7 +2797,7 @@ ], "re.kr": [ "whois.nic.or.kr", - "is not registered" + "domain was not found" ], "realestate.pl": [ "whois.dns.pl", @@ -2908,7 +2868,7 @@ "Domain not found." ], "reviews": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "rich": [ @@ -2928,7 +2888,7 @@ "No entries found" ], "rocks": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "rodeo": [ @@ -3011,10 +2971,6 @@ "whois.srs.net.nz", "220 Available" ], - "school.za": [ - "whois.co.za", - "No information available" - ], "schule": [ "whois.donuts.co", "Domain not found." @@ -3077,7 +3033,8 @@ ], "sk": [ "whois.sk-nic.sk", - "Not found" + "Not found", + "NEGATION:The Domain cannot be registered" ], "sklep.pl": [ "whois.dns.pl", @@ -3112,7 +3069,7 @@ "No entries found" ], "social": [ - "whois.unitedtld.com", + "whois.rightside.co", "Domain not found." ], "software": [ @@ -3303,10 +3260,6 @@ "whois.rotld.ro", "No entries found" ], - "tm.za": [ - "whois.co.za", - "No information available" - ], "tmp.br": [ "whois.nic.br", "No match for" @@ -3547,14 +3500,14 @@ "whois.donuts.co", "Domain not found." ], + "web.id": [ + "whois.pandi.or.id", + "DOMAIN NOT FOUND" + ], "web.ve": [ "whois.nic.ve", "No match for" ], - "web.za": [ - "whois.co.za", - "No information available" - ], "website": [ "whois.nic.website", "DOMAIN NOT FOUND" @@ -3907,4 +3860,4 @@ "whois.ksregistry.net", "not found..." ] -} \ No newline at end of file +}