├── LICENSE ├── README.md ├── example.php └── whois.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jason Ho 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP Simple Whois Data Parser 2 | An simple whois data parser in PHP. 3 | 4 | # Sample Usage 5 | 6 | ```php 7 | query($domain); 14 | 15 | if(!is_array($whoisResult)){ 16 | if(mb_substr($whoisResult, 0, 3) == "++["){ 17 | die($whoisResult); 18 | } 19 | }else{ 20 | print_r($whoisResult); 21 | } 22 | ?> 23 | ``` 24 | 25 | Another example can be found in `example.php`. 26 | 27 | # Sample Result 28 | 29 | ``` 30 | Array 31 | ( 32 | [domain] => github.com 33 | [id] => 1264983250_DOMAIN_COM-VRSN 34 | [whois_server] => Array 35 | ( 36 | [0] => whois.markmonitor.com 37 | ) 38 | 39 | [registrar_url] => Array 40 | ( 41 | [0] => http://www.markmonitor.com 42 | ) 43 | 44 | [updated] => Array 45 | ( 46 | [0] => 2015-01-08T04:00:18-0800 47 | ) 48 | 49 | [created] => Array 50 | ( 51 | [0] => 2007-10-09T11:20:50-0700 52 | ) 53 | 54 | [expires] => Array 55 | ( 56 | [0] => 2020-10-09T11:20:50-0700 57 | ) 58 | 59 | [registrar] => Array 60 | ( 61 | [0] => MarkMonitor, Inc. 62 | ) 63 | 64 | [status] => Array 65 | ( 66 | [0] => clientUpdateProhibited (https://www.icann.org/epp#clientUpdateProhibited) 67 | [1] => clientTransferProhibited (https://www.icann.org/epp#clientTransferProhibited) 68 | [2] => clientDeleteProhibited (https://www.icann.org/epp#clientDeleteProhibited) 69 | ) 70 | 71 | [dns] => Array 72 | ( 73 | [0] => ns1.p16.dynect.net 74 | [1] => ns2.p16.dynect.net 75 | [2] => ns3.p16.dynect.net 76 | [3] => ns4.p16.dynect.net 77 | ) 78 | 79 | [created_parsed] => Array 80 | ( 81 | [year] => 2007 82 | [month] => 10 83 | [day] => 9 84 | [hour] => 11 85 | [minute] => 20 86 | [second] => 50 87 | [fraction] => 0 88 | [warning_count] => 0 89 | [warnings] => Array 90 | ( 91 | ) 92 | 93 | [error_count] => 0 94 | [errors] => Array 95 | ( 96 | ) 97 | 98 | [is_localtime] => 1 99 | [zone_type] => 1 100 | [zone] => 420 101 | [is_dst] => 102 | ) 103 | 104 | [created_parsed_string] => 2007-10-09 11:20:50 105 | [expires_parsed] => Array 106 | ( 107 | [year] => 2020 108 | [month] => 10 109 | [day] => 9 110 | [hour] => 11 111 | [minute] => 20 112 | [second] => 50 113 | [fraction] => 0 114 | [warning_count] => 0 115 | [warnings] => Array 116 | ( 117 | ) 118 | 119 | [error_count] => 0 120 | [errors] => Array 121 | ( 122 | ) 123 | 124 | [is_localtime] => 1 125 | [zone_type] => 1 126 | [zone] => 420 127 | [is_dst] => 128 | ) 129 | 130 | [expires_parsed_string] => 2020-10-09 11:20:50 131 | [updated_parsed] => Array 132 | ( 133 | [year] => 2015 134 | [month] => 1 135 | [day] => 8 136 | [hour] => 4 137 | [minute] => 0 138 | [second] => 18 139 | [fraction] => 0 140 | [warning_count] => 0 141 | [warnings] => Array 142 | ( 143 | ) 144 | 145 | [error_count] => 0 146 | [errors] => Array 147 | ( 148 | ) 149 | 150 | [is_localtime] => 1 151 | [zone_type] => 1 152 | [zone] => 480 153 | [is_dst] => 154 | ) 155 | 156 | [updated_parsed_string] => 2015-01-08 04:00:18 157 | [registrant] => Array 158 | ( 159 | [name] => GitHub Hostmaster 160 | [organization] => GitHub, Inc. 161 | [address] => Array 162 | ( 163 | [0] => 88 Colin P Kelly Jr St, 164 | ) 165 | 166 | [city] => San Francisco 167 | [state_province] => CA 168 | [postal_code] => 94107 169 | [country] => US 170 | [phone] => +1.4157354488 171 | [email] => hostmaster@github.com 172 | [completely_address] => 88 Colin P Kelly Jr St, 173 | ) 174 | 175 | [admin] => Array 176 | ( 177 | [name] => GitHub Hostmaster 178 | [organization] => GitHub, Inc. 179 | [address] => Array 180 | ( 181 | [0] => 88 Colin P Kelly Jr St, 182 | ) 183 | 184 | [city] => San Francisco 185 | [state_province] => CA 186 | [postal_code] => 94107 187 | [country] => US 188 | [phone] => +1.4157354488 189 | [email] => hostmaster@github.com 190 | [completely_address] => 88 Colin P Kelly Jr St, 191 | ) 192 | 193 | [tech] => Array 194 | ( 195 | [name] => GitHub Hostmaster 196 | [organization] => GitHub, Inc. 197 | [address] => Array 198 | ( 199 | [0] => 88 Colin P Kelly Jr St, 200 | ) 201 | 202 | [city] => San Francisco 203 | [state_province] => CA 204 | [postal_code] => 94107 205 | [country] => US 206 | [phone] => +1.4157354488 207 | [email] => hostmaster@github.com 208 | [completely_address] => 88 Colin P Kelly Jr St, 209 | ) 210 | 211 | ) 212 | ``` 213 | 214 | ## By AREFLY.COM -------------------------------------------------------------------------------- /example.php: -------------------------------------------------------------------------------- 1 | query($domain); 26 | 27 | if(!is_array($whoisResult)){ 28 | if(mb_substr($whoisResult, 0, 3) == "++["){ 29 | die($whoisResult); 30 | } 31 | }else{ 32 | switch ($type){ 33 | case "json": 34 | $jsonResult = json_encode($whoisResult); 35 | echo $jsonResult; 36 | break; 37 | case "text": 38 | $textResult = $whoisClass->query($domain, 'text'); 39 | echo $textResult; 40 | break; 41 | default: 42 | print_r($whoisResult); 43 | } 44 | } 45 | ?> -------------------------------------------------------------------------------- /whois.php: -------------------------------------------------------------------------------- 1 | "whois.nic.ac", // Ascension Island 7 | // ad - Andorra - no whois server assigned 8 | "ae" => "whois.nic.ae", // United Arab Emirates 9 | "aero"=>"whois.aero", 10 | "af" => "whois.nic.af", // Afghanistan 11 | "ag" => "whois.nic.ag", // Antigua And Barbuda 12 | "ai" => "whois.ai", // Anguilla 13 | "al" => "whois.ripe.net", // Albania 14 | "am" => "whois.amnic.net", // Armenia 15 | // an - Netherlands Antilles - no whois server assigned 16 | // ao - Angola - no whois server assigned 17 | // aq - Antarctica (New Zealand) - no whois server assigned 18 | // ar - Argentina - no whois server assigned 19 | "arpa" => "whois.iana.org", 20 | "as" => "whois.nic.as", // American Samoa 21 | "asia" => "whois.nic.asia", 22 | "at" => "whois.nic.at", // Austria 23 | "au" => "whois.aunic.net", // Australia 24 | // aw - Aruba - no whois server assigned 25 | "ax" => "whois.ax", // Aland Islands 26 | "az" => "whois.ripe.net", // Azerbaijan 27 | // ba - Bosnia And Herzegovina - no whois server assigned 28 | // bb - Barbados - no whois server assigned 29 | // bd - Bangladesh - no whois server assigned 30 | "be" => "whois.dns.be", // Belgium 31 | "bg" => "whois.register.bg", // Bulgaria 32 | "bi" => "whois.nic.bi", // Burundi 33 | "biz" => "whois.biz", 34 | "bj" => "whois.nic.bj", // Benin 35 | // bm - Bermuda - no whois server assigned 36 | "bn" => "whois.bn", // Brunei Darussalam 37 | "bo" => "whois.nic.bo", // Bolivia 38 | "br" => "whois.registro.br", // Brazil 39 | "bt" => "whois.netnames.net", // Bhutan 40 | // bv - Bouvet Island (Norway) - no whois server assigned 41 | // bw - Botswana - no whois server assigned 42 | "by" => "whois.cctld.by", // Belarus 43 | "bz" => "whois.belizenic.bz", // Belize 44 | "ca" => "whois.cira.ca", // Canada 45 | "cat" => "whois.cat", // Spain 46 | "cc" => "whois.nic.cc", // Cocos (Keeling) Islands 47 | "cd" => "whois.nic.cd", // Congo, The Democratic Republic Of The 48 | // cf - Central African Republic - no whois server assigned 49 | "ch" => "whois.nic.ch", // Switzerland 50 | "ci" => "whois.nic.ci", // Cote d'Ivoire 51 | "ck" => "whois.nic.ck", // Cook Islands 52 | "cl" => "whois.nic.cl", // Chile 53 | // cm - Cameroon - no whois server assigned 54 | "cn" => "whois.cnnic.net.cn", // China 55 | "co" => "whois.nic.co", // Colombia 56 | "com" => "whois.verisign-grs.com", 57 | //"com" => "whois.iana.org", 58 | "coop" => "whois.nic.coop", 59 | // cr - Costa Rica - no whois server assigned 60 | // cu - Cuba - no whois server assigned 61 | // cv - Cape Verde - no whois server assigned 62 | // cw - Curacao - no whois server assigned 63 | "cx" => "whois.nic.cx", // Christmas Island 64 | // cy - Cyprus - no whois server assigned 65 | "cz" => "whois.nic.cz", // Czech Republic 66 | "de" => "whois.denic.de", // Germany 67 | // dj - Djibouti - no whois server assigned 68 | "dk" => "whois.dk-hostmaster.dk", // Denmark 69 | "dm" => "whois.nic.dm", // Dominica 70 | // do - Dominican Republic - no whois server assigned 71 | "dz" => "whois.nic.dz", // Algeria 72 | "ec" => "whois.nic.ec", // Ecuador 73 | "edu" => "whois.educause.edu", 74 | "ee" => "whois.eenet.ee", // Estonia 75 | "eg" => "whois.ripe.net", // Egypt 76 | // er - Eritrea - no whois server assigned 77 | "es" => "whois.nic.es", // Spain 78 | // et - Ethiopia - no whois server assigned 79 | //"eu" => "whois.eu", 80 | "eu" => "eu.whois-servers.net", 81 | "fi" => "whois.ficora.fi", // Finland 82 | // fj - Fiji - no whois server assigned 83 | // fk - Falkland Islands - no whois server assigned 84 | // fm - Micronesia, Federated States Of - no whois server assigned 85 | "fo" => "whois.nic.fo", // Faroe Islands 86 | "fr" => "whois.nic.fr", // France 87 | // ga - Gabon - no whois server assigned 88 | "gd" => "whois.nic.gd", // Grenada 89 | // ge - Georgia - no whois server assigned 90 | // gf - French Guiana - no whois server assigned 91 | "gg" => "whois.gg", // Guernsey 92 | // gh - Ghana - no whois server assigned 93 | "gi" => "whois2.afilias-grs.net", // Gibraltar 94 | "gl" => "whois.nic.gl", // Greenland (Denmark) 95 | // gm - Gambia - no whois server assigned 96 | // gn - Guinea - no whois server assigned 97 | "gov" => "whois.nic.gov", 98 | // gr - Greece - no whois server assigned 99 | // gt - Guatemala - no whois server assigned 100 | "gs" => "whois.nic.gs", // South Georgia And The South Sandwich Islands 101 | // gu - Guam - no whois server assigned 102 | // gw - Guinea-bissau - no whois server assigned 103 | "gy" => "whois.registry.gy", // Guyana 104 | "hk" => "whois.hkirc.hk", // Hong Kong 105 | // hm - Heard and McDonald Islands (Australia) - no whois server assigned 106 | "hn" => "whois.nic.hn", // Honduras 107 | "hr" => "whois.dns.hr", // Croatia 108 | "ht" => "whois.nic.ht", // Haiti 109 | "hu" => "whois.nic.hu", // Hungary 110 | // id - Indonesia - no whois server assigned 111 | "ie" => "whois.domainregistry.ie", // Ireland 112 | "il" => "whois.isoc.org.il", // Israel 113 | "im" => "whois.nic.im", // Isle of Man 114 | "in" => "whois.inregistry.net", // India 115 | "info" => "whois.afilias.net", 116 | "int" => "whois.iana.org", 117 | "io" => "whois.nic.io", // British Indian Ocean Territory 118 | "iq" => "whois.cmc.iq", // Iraq 119 | "ir" => "whois.nic.ir", // Iran, Islamic Republic Of 120 | "is" => "whois.isnic.is", // Iceland 121 | "it" => "whois.nic.it", // Italy 122 | "je" => "whois.je", // Jersey 123 | // jm - Jamaica - no whois server assigned 124 | // jo - Jordan - no whois server assigned 125 | "jobs" => "jobswhois.verisign-grs.com", 126 | "jp" => "whois.jprs.jp", // Japan 127 | "ke" => "whois.kenic.or.ke", // Kenya 128 | "kg" => "www.domain.kg", // Kyrgyzstan 129 | // kh - Cambodia - no whois server assigned 130 | "ki" => "whois.nic.ki", // Kiribati 131 | // km - Comoros - no whois server assigned 132 | // kn - Saint Kitts And Nevis - no whois server assigned 133 | // kp - Korea, Democratic People's Republic Of - no whois server assigned 134 | "kr" => "whois.kr", // Korea, Republic Of 135 | // kw - Kuwait - no whois server assigned 136 | // ky - Cayman Islands - no whois server assigned 137 | "kz" => "whois.nic.kz", // Kazakhstan 138 | "la" => "whois.nic.la", // Lao People's Democratic Republic 139 | // lb - Lebanon - no whois server assigned 140 | // lc - Saint Lucia - no whois server assigned 141 | "li" => "whois.nic.li", // Liechtenstein 142 | // lk - Sri Lanka - no whois server assigned 143 | "lt" => "whois.domreg.lt", // Lithuania 144 | "lu" => "whois.dns.lu", // Luxembourg 145 | "lv" => "whois.nic.lv", // Latvia 146 | "ly" => "whois.nic.ly", // Libya 147 | "ma" => "whois.iam.net.ma", // Morocco 148 | // mc - Monaco - no whois server assigned 149 | "md" => "whois.nic.md", // Moldova 150 | "me" => "whois.nic.me", // Montenegro 151 | "mg" => "whois.nic.mg", // Madagascar 152 | // mh - Marshall Islands - no whois server assigned 153 | "mil" => "whois.nic.mil", 154 | // mk - Macedonia, The Former Yugoslav Republic Of - no whois server assigned 155 | "ml" => "whois.dot.ml", // Mali 156 | // mm - Myanmar - no whois server assigned 157 | "mn" => "whois.nic.mn", // Mongolia 158 | "mo" => "whois.monic.mo", // Macao 159 | "mobi" => "whois.dotmobiregistry.net", 160 | "mp" => "whois.nic.mp", // Northern Mariana Islands 161 | // mq - Martinique (France) - no whois server assigned 162 | // mr - Mauritania - no whois server assigned 163 | "ms" => "whois.nic.ms", // Montserrat 164 | // mt - Malta - no whois server assigned 165 | "mu" => "whois.nic.mu", // Mauritius 166 | "museum" => "whois.museum", 167 | // mv - Maldives - no whois server assigned 168 | // mw - Malawi - no whois server assigned 169 | "mx" => "whois.mx", // Mexico 170 | "my" => "whois.domainregistry.my", // Malaysia 171 | // mz - Mozambique - no whois server assigned 172 | "na" => "whois.na-nic.com.na", // Namibia 173 | "name" => "whois.nic.name", 174 | "nc" => "whois.nc", // New Caledonia 175 | // ne - Niger - no whois server assigned 176 | "net" => "whois.verisign-grs.net", 177 | "nf" => "whois.nic.nf", // Norfolk Island 178 | "ng" => "whois.nic.net.ng", // Nigeria 179 | // ni - Nicaragua - no whois server assigned 180 | "nl" => "whois.domain-registry.nl", // Netherlands 181 | "no" => "whois.norid.no", // Norway 182 | // np - Nepal - no whois server assigned 183 | // nr - Nauru - no whois server assigned 184 | "nu" => "whois.nic.nu", // Niue 185 | "nz" => "whois.srs.net.nz", // New Zealand 186 | "om" => "whois.registry.om", // Oman 187 | //"org" => "whois.pir.org", 188 | "org" => "org.whois-servers.net", 189 | // pa - Panama - no whois server assigned 190 | "pe" => "kero.yachay.pe", // Peru 191 | "pf" => "whois.registry.pf", // French Polynesia 192 | // pg - Papua New Guinea - no whois server assigned 193 | // ph - Philippines - no whois server assigned 194 | // pk - Pakistan - no whois server assigned 195 | "pl" => "whois.dns.pl", // Poland 196 | "pm" => "whois.nic.pm", // Saint Pierre and Miquelon (France) 197 | // pn - Pitcairn (New Zealand) - no whois server assigned 198 | "post" => "whois.dotpostregistry.net", 199 | "pr" => "whois.nic.pr", // Puerto Rico 200 | "pro" => "whois.dotproregistry.net", 201 | // ps - Palestine, State of - no whois server assigned 202 | "pt" => "whois.dns.pt", // Portugal 203 | "pw" => "whois.nic.pw", // Palau 204 | // py - Paraguay - no whois server assigned 205 | "qa" => "whois.registry.qa", // Qatar 206 | "re" => "whois.nic.re", // Reunion (France) 207 | "ro" => "whois.rotld.ro", // Romania 208 | "rs" => "whois.rnids.rs", // Serbia 209 | "ru" => "whois.tcinet.ru", // Russian Federation 210 | // rw - Rwanda - no whois server assigned 211 | "sa" => "whois.nic.net.sa", // Saudi Arabia 212 | "sb" => "whois.nic.net.sb", // Solomon Islands 213 | "sc" => "whois2.afilias-grs.net", // Seychelles 214 | // sd - Sudan - no whois server assigned 215 | "se" => "whois.iis.se", // Sweden 216 | "sg" => "whois.sgnic.sg", // Singapore 217 | "sh" => "whois.nic.sh", // Saint Helena 218 | "si" => "whois.arnes.si", // Slovenia 219 | "sk" => "whois.sk-nic.sk", // Slovakia 220 | // sl - Sierra Leone - no whois server assigned 221 | "sm" => "whois.nic.sm", // San Marino 222 | "sn" => "whois.nic.sn", // Senegal 223 | "so" => "whois.nic.so", // Somalia 224 | // sr - Suriname - no whois server assigned 225 | "st" => "whois.nic.st", // Sao Tome And Principe 226 | "su" => "whois.tcinet.ru", // Russian Federation 227 | // sv - El Salvador - no whois server assigned 228 | "sx" => "whois.sx", // Sint Maarten (dutch Part) 229 | "sy" => "whois.tld.sy", // Syrian Arab Republic 230 | // sz - Swaziland - no whois server assigned 231 | "tc" => "whois.meridiantld.net", // Turks And Caicos Islands 232 | // td - Chad - no whois server assigned 233 | "tel" => "whois.nic.tel", 234 | "tf" => "whois.nic.tf", // French Southern Territories 235 | // tg - Togo - no whois server assigned 236 | "th" => "whois.thnic.co.th", // Thailand 237 | "tj" => "whois.nic.tj", // Tajikistan 238 | "tk" => "whois.dot.tk", // Tokelau 239 | "tl" => "whois.nic.tl", // Timor-leste 240 | "tm" => "whois.nic.tm", // Turkmenistan 241 | "tn" => "whois.ati.tn", // Tunisia 242 | "to" => "whois.tonic.to", // Tonga 243 | "tp" => "whois.nic.tl", // Timor-leste 244 | "tr" => "whois.nic.tr", // Turkey 245 | "travel" => "whois.nic.travel", 246 | // tt - Trinidad And Tobago - no whois server assigned 247 | "tv" => "tvwhois.verisign-grs.com", // Tuvalu 248 | "tw" => "whois.twnic.net.tw", // Taiwan 249 | "tz" => "whois.tznic.or.tz", // Tanzania, United Republic Of 250 | "ua" => "whois.ua", // Ukraine 251 | "ug" => "whois.co.ug", // Uganda 252 | "uk" => "whois.nic.uk", // United Kingdom 253 | "us" => "whois.nic.us", // United States 254 | "uy" => "whois.nic.org.uy", // Uruguay 255 | "uz" => "whois.cctld.uz", // Uzbekistan 256 | // va - Holy See (vatican City State) - no whois server assigned 257 | "vc" => "whois2.afilias-grs.net", // Saint Vincent And The Grenadines 258 | "ve" => "whois.nic.ve", // Venezuela 259 | "vg" => "whois.adamsnames.tc", // Virgin Islands, British 260 | // vi - Virgin Islands, US - no whois server assigned 261 | // vn - Viet Nam - no whois server assigned 262 | // vu - Vanuatu - no whois server assigned 263 | "wf" => "whois.nic.wf", // Wallis and Futuna 264 | "ws" => "whois.website.ws", // Samoa 265 | "xxx" => "whois.nic.xxx", 266 | // ye - Yemen - no whois server assigned 267 | "yt" => "whois.nic.yt", // Mayotte 268 | "yu" => "whois.ripe.net"]; 269 | //"中文" => "whois.afilias-srs.net"]; 270 | 271 | private $returnType = ""; 272 | 273 | public function query($domain, $type = 'array', $raw = false){ 274 | 275 | $this->returnType = $type; 276 | 277 | $domain = strip_tags($domain); 278 | 279 | $explodedDomain = explode(".", $domain); 280 | $explodedCount = count($explodedDomain); 281 | if(empty($explodedDomain[$explodedCount-1])){ 282 | return "++[ERROR_NOT_A_DOMAIN]++"; 283 | } 284 | 285 | $domainArr = array_slice($explodedDomain, -2); 286 | $domain = implode(".", $domainArr); 287 | //$domain = $explodedDomain[$explodedCount-2].".".$explodedDomain[$explodedCount-1]; 288 | 289 | if($explodedCount >= 3){ 290 | if(array_key_exists($explodedDomain[$explodedCount-1], $this->whoisServers)){ 291 | if(array_key_exists($explodedDomain[$explodedCount-2], $this->whoisServers)){ 292 | //$domain = $explodedDomain[$explodedCount-3].".".$explodedDomain[$explodedCount-2].".".$explodedDomain[$explodedCount-1]; 293 | $domainArr = array_slice($explodedDomain, -3); 294 | $domain = implode(".", $domainArr); 295 | } 296 | } 297 | } 298 | 299 | $tld = substr($domain, strrpos($domain, '.') + 1); 300 | 301 | $data = []; 302 | 303 | $data = $this->getWhoisResult($domain, $tld); 304 | 305 | if(mb_substr($data[0], 0, 3) == "++["){ 306 | return $data[0]; 307 | }else{ 308 | $whoisServerFromWhois = $this->parse($data, $domain, 'Domain Name:', ['Whois Server' => 'whois_server'], true); 309 | if(!empty($whoisServerFromWhois['whois_server'][0])){ 310 | $data = $this->getWhoisResult($domain, $tld, $whoisServerFromWhois['whois_server'][0]); 311 | } 312 | 313 | $parsedResult = $this->parse_domain($data, $domain, $tld); 314 | 315 | if(!empty($parsedResult[0])){ 316 | if(mb_substr($parsedResult[0], 0, 3) == "++["){ 317 | return $parsedResult[0]; 318 | } 319 | }else{ 320 | if($this->returnType == "text"){ 321 | return trim(implode("\n", $data)); 322 | }else{ 323 | return $parsedResult; 324 | } 325 | } 326 | } 327 | } 328 | 329 | private function getWhoisResult($domain = '', $tld = '', $serverUrl = '') { 330 | if (empty($domain)) { 331 | return ["++[ERROR_NOTHING_ENTERED]++"]; 332 | } 333 | if(strpos($domain, ".") == false){ 334 | return ["++[ERROR_NOT_A_DOMAIN]++"]; 335 | } 336 | 337 | if (!array_key_exists($tld, $this->whoisServers)){ 338 | return ["++[ERROR_UNSUPPORTED_TLD]++"]; 339 | } 340 | 341 | if(empty($serverUrl)){ 342 | $serverUrl = $this->whoisServers[$tld]; 343 | } 344 | $f = fsockopen($serverUrl, 43); 345 | 346 | $needToBeAddEqual = ["whois.verisign-grs.com", "whois.verisign-grs.net"]; 347 | 348 | if (in_array($serverUrl, $needToBeAddEqual)){ 349 | fputs($f, "=" . $domain . "\r\n"); 350 | }else{ 351 | fputs($f, $domain . "\r\n"); 352 | } 353 | 354 | /*else if($tld == "中文"){ 355 | $domain = str_replace(".中文", ".xn--fiq228c", $domain); 356 | fputs($f, $domain . "\r\n"); 357 | }*/ 358 | 359 | $data = []; 360 | 361 | while (!feof($f)){ 362 | $data[] = rtrim(fgets($f), "\n"); 363 | } 364 | 365 | if($this->returnType != "text"){ 366 | $stringsExistToMeanAvailable = ["No Match", "No match", "No match for", "Status: AVAILABLE", "NOT FOUND", "Not found", "No Found", "No information available about domain name", "No matching record.", "No entries found in the AFNIC Database.", "The domain has not been registered.", "Status: free"]; 367 | $stringsExistToMeanErrorInput = ["Incorrect input, please try again.", "Error for \""]; 368 | $stringsExistToMeanWaitSomeTime = ["Please maintain at least " => "Please maintain at least %d-second time before starting another enquiry."]; 369 | 370 | foreach($data as $eachLine){ 371 | foreach($stringsExistToMeanAvailable as $stringExistToMeanAvailable){ 372 | if(strpos($eachLine, $stringExistToMeanAvailable) !== false){ 373 | return ["++[ERROR_NO_MATCH]++"]; 374 | } 375 | } 376 | foreach($stringsExistToMeanErrorInput as $stringExistToMeanErrorInput){ 377 | if(strpos($eachLine, $stringExistToMeanErrorInput) !== false){ 378 | return ["++[ERROR_INPUT]++"]; 379 | } 380 | } 381 | foreach($stringsExistToMeanWaitSomeTime as $stringExistToMeanWaitSomeTime => $sscanfFullString){ 382 | if(strpos($eachLine, $stringExistToMeanWaitSomeTime) !== false){ 383 | if($sscanfFullString == "N/A"){ 384 | return ["++[PLZ_WAIT_SOME_TIME]++"]; 385 | }else{ 386 | sscanf($eachLine, $sscanfFullString, $second); 387 | if(!empty($second)){ 388 | return ["++[PLZ_WAIT_".$second."_SEC]++"]; 389 | }else{ 390 | return ["++[PLZ_WAIT_SOME_TIME]++"]; 391 | } 392 | } 393 | } 394 | } 395 | } 396 | } 397 | 398 | //print_r($data); 399 | 400 | /*if ($raw === true) 401 | { 402 | return $data; 403 | }*/ 404 | 405 | return $data; 406 | } 407 | 408 | private function parse($data, $domain, $domainWord, $keywords, $breakOnEnter) 409 | { 410 | $found = false; 411 | $domainWordLen = strlen($domainWord); 412 | 413 | $res = []; 414 | 415 | foreach ($data AS $d) 416 | { 417 | $d = trim($d); 418 | 419 | if ($d == '') 420 | { 421 | if ($breakOnEnter) 422 | { 423 | $found = false; 424 | } 425 | continue; 426 | } 427 | 428 | $pos = strpos($d, $domainWord); 429 | if ($pos !== false) 430 | { 431 | $dom = strtolower(trim(substr($d, $pos + $domainWordLen))); 432 | if ($dom == $domain) 433 | { 434 | $found = true; 435 | } 436 | } 437 | 438 | if ($found) 439 | { 440 | $pos = strpos($d, ':'); 441 | if ($pos !== false) 442 | { 443 | $keyword = substr($d, 0, $pos); 444 | 445 | if (isset($keywords[$keyword])) 446 | { 447 | $t = trim(substr($d, $pos+1)); 448 | if ($t != '') 449 | { 450 | $res[$keywords[$keyword]][] = $t; 451 | } 452 | } 453 | else 454 | { 455 | $keyword = ''; 456 | } 457 | } 458 | else if ($keyword) 459 | { 460 | $res[$keywords[$keyword]][] = $d; 461 | } 462 | } 463 | } 464 | return $res; 465 | } 466 | 467 | private function parse_domain($data, $domain, $tld) 468 | { 469 | $domainWords = [ 470 | 'def' => 'Domain Name:', 471 | 'com' => 'Domain Name:', 472 | 'org' => 'Domain Name:', 473 | 'net' => 'Domain Name:', 474 | 'biz' => 'Domain Name:', 475 | 'info' => 'Domain Name:', 476 | 'name' => 'Domain Name:', 477 | 'asia' => 'Domain Name:', 478 | 'pl' => 'DOMAIN NAME:', 479 | 'de' => 'Domain:', 480 | 'fr' => 'domain:', 481 | 'eu' => 'Domain:', 482 | 'us' => 'Domain Name:', 483 | 'cn' => 'Domain Name:', 484 | 'hk' => 'Domain Name:', 485 | 'tw' => 'Domain Name:' 486 | ]; 487 | 488 | $domainsKeywords = [ 489 | [ 'id' => ['Domain ID', 'Domain Name ID', 'Registry Domain ID', 'ROID'] ], 490 | [ 'domain' => ['Domain name', 'Domain Name', 'DOMAIN NAME', 'Domain', 'domain'] ], 491 | [ 'bundled_domain' => ['Bundled Domain Name'] ], 492 | [ 'dns' => ['Name Server', 'Nameservers', 'Name servers', 'Name Servers Information', 'Domain servers in listed order', 'nserver', 'nameservers'] ], 493 | [ 'registrar' => ['Registrar', 'registrar', 'Registrant', 'Registrar Name', 'Created by Registrar'] ], 494 | [ 'registrar_url' => ['Registrar URL', 'Registrar URL (registration services)'] ], 495 | [ 'sponsoring_registrar' => [ 'Sponsoring Registrar'] ], 496 | [ 'whois_server' => ['Whois Server', 'WHOIS SERVER', 'Registrar WHOIS Server'] ], 497 | [ 'created' => ['Creation Date', 'Created On', 'Registration Time', 'Domain Create Date', 'Domain Registration Date', 'Domain Name Commencement Date', 'created'] ], 498 | [ 'updated' => ['last-update', 'Updated Date', 'Domain Last Updated Date', 'last modified'] ], 499 | [ 'expires' => ['Expiry Date', 'Expiration Date', 'Expiration Time', 'Domain Expiration Date', 'Registrar Registration Expiration Date', 'Record expires on', 'Registry Expiry Date', 'renewal date'] ], 500 | [ 'status' => ['Status', 'status', 'Domain Status'] ], 501 | ]; 502 | 503 | $toBeParseKeywords = []; 504 | 505 | foreach ($domainsKeywords as $domainKeywords){ 506 | foreach ($domainKeywords as $var => $keywords){ 507 | foreach($keywords as $keyword){ 508 | $toBeParseKeywords[$keyword] = $var; 509 | } 510 | } 511 | } 512 | 513 | $contactInfoCategories = [ 514 | [ 'id' => ['ID'] ], 515 | [ 'name' => ['Name'] ], 516 | [ 'organization' => ['Organization'] ], 517 | [ 'city' => ['City'] ], 518 | [ 'country' => ['Country', 'Country/Economy'] ], 519 | [ 'address' => ['Street', 'Address', 'Address1', 'Address2', 'Address3', 'Address4'] ], 520 | [ 'state_province' => ['State/Province'] ], 521 | [ 'postal_code' => ['Postal Code'] ], 522 | [ 'email' => ['Email'] ], 523 | [ 'phone' => ['Phone', 'Phone Number'] ], 524 | [ 'phone_ext' => ['Phone Ext', 'Phone Ext.'] ], 525 | [ 'fax' => ['Fax', 'FAX', 'Facsimile Number'] ], 526 | [ 'fax_ext' => ['Fax Ext', 'FAX Ext.'] ] 527 | ]; 528 | 529 | $contactInfoKeywords = [ 530 | [ 'admin' => ['Admin', 'Administrative', 'Administrative Contact'] ], 531 | [ 'registrant' => ['Registrant'] ], 532 | [ 'tech' => ['Tech', 'Technical', 'Technical Contact'] ], 533 | [ 'billing' => ['Bill', 'Billing', 'Billing Contact'] ] 534 | ]; 535 | 536 | foreach ($contactInfoKeywords as $contactInfoKeyword){ 537 | foreach($contactInfoKeyword as $contactKey => $contactKeywords){ 538 | foreach($contactKeywords as $contactKeyword){ 539 | foreach ($contactInfoCategories as $contactInfoCategory){ 540 | foreach ($contactInfoCategory as $var => $keywords){ 541 | foreach($keywords as $keyword){ 542 | $toBeParseKeywords[$contactKeyword." ".$keyword] = $contactKey."_".$var; 543 | } 544 | } 545 | } 546 | } 547 | } 548 | } 549 | 550 | if(array_key_exists($tld, $domainWords)){ 551 | $domainWord = $domainWords[$tld]; 552 | }else{ 553 | $domainWord = $domainWords['def']; 554 | } 555 | 556 | $data = array_filter(array_map("Whois::ifWhiteSpace", $data)); 557 | //print_r($data); 558 | $parseResult = $this->parse($data, $domain, $domainWord, $toBeParseKeywords, true); 559 | 560 | $needToBeSingles = ["domain", "id"]; 561 | foreach($needToBeSingles as $needToBeSingle){ 562 | if(!empty($parseResult[$needToBeSingle])){ 563 | $parseResult[$needToBeSingle] = $parseResult[$needToBeSingle][0]; 564 | } 565 | } 566 | if(!empty($parseResult['domain'])){ 567 | $parseResult['domain'] = strtolower($parseResult['domain']); 568 | } 569 | 570 | $needToBeParsedTimeKeys = ['created', 'expires', 'updated']; 571 | foreach($needToBeParsedTimeKeys as $needToBeParsedTimeKey){ 572 | if(!empty($parseResult[$needToBeParsedTimeKey])){ 573 | $domainTime = $parseResult[$needToBeParsedTimeKey][0]; 574 | //if ( (date_parse($domainTime)['warning_count'] == 0) && (date_parse($domainTime)['error_count'] == 0) ) { 575 | if (date_parse($domainTime)['error_count'] == 0) { 576 | $parsed_date = date_parse($domainTime); 577 | $parseResult[$needToBeParsedTimeKey."_parsed"] = $parsed_date; 578 | $date_string = date('Y-m-d H:i:s', mktime($parsed_date['hour'], $parsed_date['minute'], $parsed_date['second'], $parsed_date['month'], $parsed_date['day'], $parsed_date['year'])); 579 | $parseResult[$needToBeParsedTimeKey."_parsed_string"] = $date_string; 580 | }else{ 581 | $formatedTime = $domainTime; 582 | $formatedTime = str_replace("T", " ", $formatedTime); 583 | $formatedTime = str_replace("Z", " ", $formatedTime); 584 | $formatedTime = trim($formatedTime); 585 | $parsed_date = date_parse_from_format("Y-m-d H:i:s.u", $formatedTime); 586 | $parseResult[$needToBeParsedTimeKey."_parsed"] = $parsed_date; 587 | $date_string = date('Y-m-d H:i:s', mktime($parsed_date['hour'], $parsed_date['minute'], $parsed_date['second'], $parsed_date['month'], $parsed_date['day'], $parsed_date['year'])); 588 | $parseResult[$needToBeParsedTimeKey."_parsed_string"] = $date_string; 589 | } 590 | } 591 | } 592 | 593 | foreach($parseResult as $eachParseResultKey => $eachParseResult){ 594 | if (substr($eachParseResultKey, 0, 6) == "admin_") { 595 | unset($parseResult[$eachParseResultKey]); 596 | $key = substr($eachParseResultKey, 6); 597 | if($key != "address"){ 598 | $eachParseResult = $eachParseResult[0]; 599 | } 600 | $parseResult['admin'][$key] = $eachParseResult; 601 | } 602 | if (substr($eachParseResultKey, 0, 11) == "registrant_") { 603 | unset($parseResult[$eachParseResultKey]); 604 | $key = substr($eachParseResultKey, 11); 605 | if($key != "address"){ 606 | $eachParseResult = $eachParseResult[0]; 607 | } 608 | $parseResult['registrant'][$key] = $eachParseResult; 609 | } 610 | if (substr($eachParseResultKey, 0, 5) == "tech_") { 611 | unset($parseResult[$eachParseResultKey]); 612 | $key = substr($eachParseResultKey, 5); 613 | if($key != "address"){ 614 | $eachParseResult = $eachParseResult[0]; 615 | } 616 | $parseResult['tech'][$key] = $eachParseResult; 617 | } 618 | if (substr($eachParseResultKey, 0, 8) == "billing_") { 619 | unset($parseResult[$eachParseResultKey]); 620 | $key = substr($eachParseResultKey, 8); 621 | if($key != "address"){ 622 | $eachParseResult = $eachParseResult[0]; 623 | } 624 | $parseResult['bill'][$key] = $eachParseResult; 625 | } 626 | } 627 | 628 | $needToBeLowerCasedValueFathers = ['registrant', 'admin', 'tech', 'billing']; 629 | foreach($needToBeLowerCasedValueFathers as $needToBeLowerCasedValueFather){ 630 | if(!empty($parseResult[$needToBeLowerCasedValueFather])){ 631 | $needToBeLowerCasedValue = $parseResult[$needToBeLowerCasedValueFather]['email']; 632 | if(!empty($needToBeLowerCasedValue)){ 633 | $parseResult[$needToBeLowerCasedValueFather]['email'] = strtolower($parseResult[$needToBeLowerCasedValueFather]['email']); 634 | } 635 | } 636 | } 637 | 638 | $needToAddCompletelyAddressArrays = ['registrant', 'admin', 'tech', 'billing']; 639 | foreach($needToAddCompletelyAddressArrays as $needToAddCompletelyAddressArray){ 640 | if(!empty($parseResult[$needToAddCompletelyAddressArray])){ 641 | if(!empty($parseResult[$needToAddCompletelyAddressArray]["address"])){ 642 | $parseResult[$needToAddCompletelyAddressArray]["completely_address"] = implode(", ", $parseResult[$needToAddCompletelyAddressArray]["address"]); 643 | /* WILL CITY & COUNTRY WILL BE INCLUDE IN FULL ADDRESS? */ 644 | /*$allExtraInfomations = ["city", "country"]; 645 | foreach($allExtraInfomations as $extraInfomation){ 646 | if(!empty($parseResult[$needToAddCompletelyAddressArray][$extraInfomation])){ 647 | $parseResult[$needToAddCompletelyAddressArray]["completely_address"] .= ", ".$parseResult[$needToAddCompletelyAddressArray][$extraInfomation]; 648 | } 649 | }*/ 650 | $parseResult[$needToAddCompletelyAddressArray]["completely_address"] = ucwords(strtolower($parseResult[$needToAddCompletelyAddressArray]["completely_address"])); 651 | } 652 | } 653 | } 654 | 655 | if($this->returnType != "text"){ 656 | if(empty($parseResult)){ 657 | return ["++[ERROR_NOTHING_IN_ARRAY]++"]; 658 | } 659 | } 660 | 661 | return $parseResult; 662 | } 663 | 664 | private function ifWhiteSpace($el){ 665 | return trim($el, " "); 666 | } 667 | } --------------------------------------------------------------------------------