-
-
Save haipham/e005860927f3daa1ff5d38cf7666522d to your computer and use it in GitHub Desktop.
Get Detail Data From Whois Domain Result (#PCRE REGULAR EXPRESSION)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // result data | |
| $resultString = 'Fill With Whois Result'; | |
| // Domain .be fixer | |
| $resultString = str_replace("\r", "", $resultString); | |
| if (strpos($resultString, ":\n\t")) { | |
| $arr = explode("\n", $resultString); | |
| $currentKey = null; | |
| foreach ($arr as $key => $value) { | |
| $arr[$key] = trim($value); | |
| if (trim($value) == '' || substr(trim($value), 0, 1) == '%') { | |
| continue; | |
| } | |
| if (substr(rtrim($arr[$key]), -1) === ':' | |
| && isset($arr[$key+1]) | |
| && substr($arr[$key+1], 0, 1) === "\t" | |
| ) { | |
| unset($arr[$key]); | |
| $currentKey = trim($value); | |
| if (preg_match('/\t[a-z0-9\s]+\s*\:/i', $arr[$key+1])) { | |
| $currentKey = rtrim($currentKey, ':'); | |
| } | |
| continue; | |
| } | |
| if (substr($value, 0, 1) === "\t") { | |
| $arr[$key] = "{$currentKey} {$arr[$key]}"; | |
| } | |
| } | |
| $resultString = implode("\n", $arr); | |
| unset($arr); | |
| } | |
| // fix for DNSSEC | |
| // DNSS SEC DATA : (DS Key Tag) (Algorithm) (Digest Type) (Digest) | |
| // example : 12345 8 1 123456789FABCDE01234ABCDEF | |
| if (stripos($data, 'Algorithm') !== false && stripos($data, 'Digest') !== false) { | |
| $placeHolder = "[__".microtime(true)."__]"; | |
| $resultString = preg_replace_callback( | |
| '/ | |
| (?P<name> | |
| (?: | |
| DS\s*Key(?:\s*Tag)? | |
| | Algorithm | |
| | Digest\s*Type | |
| | Digest\s* | |
| ) | |
| )\s*(?P<selector>[0-9]+)(?:[^\:]+)?\:(?P<values>[0-9a-f]+)[^\n]* | |
| /mxi', | |
| function ($match) use ($placeHolder) { | |
| if (strpos($match['name'], 'DS') !== false) { | |
| return "DNSSEC DS Data: {$match['values']}"; | |
| } | |
| return $placeHolder.$match['values']; | |
| }, | |
| $resultString | |
| ); | |
| $resultString = str_replace(["\n{$placeHolder}", $placeHolder,], " ", $resultString); | |
| } | |
| preg_match_all( | |
| '~ | |
| # dnssec | |
| DNSSEC\s*\:(?P<domain_dnssec_status>[^\n]+) | |
| | DNSSEC\s+(?:[^\:]+)\s*\:(?P<domain_dnssec>[^\n]+) | |
| # Domain ID | |
| | (?:Registry)?\s*Domain\s+ID\:(?P<domain_id>[^\n]+) | |
| # Date | |
| | (Updated?\s*Date|Last\s*Updated?)(?:([^\:]+)?On)?(?:[^\:]+)?:(?P<date_updated>[^\n]+) | |
| | (?:Creat(?:e[ds]?|ions?)\s*(On|Date)|Registered)(?:[^\:]+)?:(?P<date_created>[^\n]+) | |
| | Expir(?:e[ds]?|y|ations?)\s*Date(?:([^\:]+)?On)?\s*:(?P<date_expired>[^\n]+) | |
| # last update db | |
| | (?:\>\>\>?)?\s* | |
| (Last\s*Update\s*(?:[a-z0-9\s]+)?Whois\s*Database)\s* | |
| \:\s*(?P<date_last_update_db>(?:[0-9]+[0-9\-\:\s\+TZGMU]+)?) | |
| | (?:Domain\s*)?(?:Flags|Status)\s*:(?P<domain_status>[^\n]+) | |
| # Other | |
| | Referral(?:[^\:]+)?\s*\:(?P<referral>[^\n]+) | |
| | Reseller(?:[^\:]+)?\s*\:(?P<reseller>[^\n]+) | |
| # Name Server | |
| | (?:N(?:ame)?\s*\_?Servers?)\s*\:(?P<name_server>[^\n]+) | |
| # Whois Server | |
| | Whois\s*Server\s*\:(?P<whois_server>[^\n]+) | |
| # Registrar Data | |
| | Registr(?:ar|y)\s*ID\s*\:(?P<registrar_id>[^\n]+) | |
| | Registr(?:ar|y)(?:\s*IANA)(?:[^\:]+)?ID\s*\:(?P<registrar_iana_id>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?Name(?:[^\:]+)?\:(?P<registrar_name>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?(?:Organiz[^\:]+|Company)(?:[^\:]+)?\:(?P<registrar_org>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?(?:Contact\s*)?Email(?:[^\:]+)?\:(?P<registrar_email>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?Country(?:[^\:]+)?\:(?P<registrar_country>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?(?:State|Province)(?:[^\:]+)?\:(?P<registrar_state>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?City(?:[^\:]+)?\:(?P<registrar_city>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?(?:Street|Addre)(?:[^\:]+)?\:(?P<registrar_street>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?(?:Postal|Post)(?:[^\:]+)?\:(?P<registrar_postal>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?Phone(?:[^\:]+)?\:(?P<registrar_phone>[^\n]+) | |
| | Registr(?:ar|y)\s*(?:Contact(?:[^\:]+)?)?Fax(?:[^\:]+)?\:(?P<registrar_fax>[^\n]+) | |
| | (?:Registr(?:ar|y)\s*)?Abuse\s*[^\:]+e?mail(?:[^\:]+)?\:(?P<registrar_abuse_mail>[^\n]+) | |
| | (?:Registr(?:ar|y)\s*)?Abuse\s*[^\:]+phone(?:[^\:]+)?\:(?P<registrar_abuse_phone>[^\n]+) | |
| # Registrant Data | |
| | (?:Registrant|owner)\s*ID(?:[^\:]+)?\:(?P<registrant_id>[^\n]+) | |
| | (?:Registrant|owner)\s*Name(?:[^\:]+)?\:(?P<registrant_name>[^\n]+) | |
| | (?:Registrant|owner)\s*(?:Organiz[^\:]+|Company)(?:[^\:]+)?\:(?P<registrant_org>[^\n]+) | |
| | (?:Registrant|owner)\s*(?:Contact\s*)?Email(?:[^\:]+)?\:(?P<registrant_email>[^\n]+) | |
| | (?:Registrant|owner)\s*Country(?:[^\:]+)?\:(?P<registrant_country>[^\n]+) | |
| | (?:Registrant|owner)\s*(?:State|Province)(?:[^\:]+)?\:(?P<registrant_state>[^\n]+) | |
| | (?:Registrant|owner)\s*City(?:[^\:]+)?\:(?P<registrant_city>[^\n]+) | |
| | (?:Registrant|owner)\s*(?:Street|Addre)(?:[^\:]+)?\:(?P<registrant_street>[^\n]+) | |
| | (?:Registrant|owner)\s*(?:Postal|Post)(?:[^\:]+)?\:(?P<registrant_postal>[^\n]+) | |
| | (?:Registrant|owner)\s*Phone(?:[^\:]+)?\:(?P<registrant_phone>[^\n]+) | |
| | (?:Registrant|owner)\s*Fax(?:[^\:]+)?\:(?P<registrant_fax>[^\n]+) | |
| # Registrant Billing | |
| | (?:Bill(?:s|ing)?)\s*ID(?:[^\:]+)?\:(?P<billing_id>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*Name(?:[^\:]+)?\:(?P<billing_name>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*(?:Organiz[^\:]+|Company)(?:[^\:]+)?\:(?P<billing_org>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*(?:Contact\s*)?Email(?:[^\:]+)?\:(?P<billing_email>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*Country(?:[^\:]+)?\:(?P<billing_country>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*(?:State|Province)(?:[^\:]+)?\:(?P<billing_state>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*City(?:[^\:]+)?\:(?P<billing_city>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*(?:Street|Addre)(?:[^\:]+)?\:(?P<billing_street>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*(?:Postal|Post)(?:[^\:]+)?\:(?P<billing_postal>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*Phone(?:[^\:]+)?\:(?P<billing_phone>[^\n]+) | |
| | (?:Bill(?:s|ing)?)\s*Fax(?:[^\:]+)?\:(?P<billing_fax>[^\n]+) | |
| # Registrant Admin | |
| | (?:Admin)\s*ID(?:[^\:]+)?\:(?P<admin_id>[^\n]+) | |
| | (?:Admin)\s*Name(?:[^\:]+)?\:(?P<admin_name>[^\n]+) | |
| | (?:Admin)\s*(?:Organiz[^\:]+|Company)(?:[^\:]+)?\:(?P<admin_org>[^\n]+) | |
| | (?:Admin)\s*(?:Contact\s*)?Email(?:[^\:]+)?\:(?P<admin_email>[^\n]+) | |
| | (?:Admin)\s*Country(?:[^\:]+)?\:(?P<admin_country>[^\n]+) | |
| | (?:Admin)\s*(?:State|Province)(?:[^\:]+)?\:(?P<admin_state>[^\n]+) | |
| | (?:Admin)\s*City(?:[^\:]+)?\:(?P<admin_city>[^\n]+) | |
| | (?:Admin)\s*(?:Street|Addre)(?:[^\:]+)?\:(?P<admin_street>[^\n]+) | |
| | (?:Admin)\s*(?:Postal|Post)(?:[^\:]+)?\:(?P<admin_postal>[^\n]+) | |
| | (?:Admin)\s*Phone(?:[^\:]+)?\:(?P<admin_phone>[^\n]+) | |
| | (?:Admin)\s*Fax(?:[^\:]+)?\:(?P<admin_fax>[^\n]+) | |
| # Registrant tech | |
| | (?:Tech(?:[^\:]+)?)\s*ID(?:[^\:]+)?\:(?P<tech_id>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*Name(?:[^\:]+)?\:(?P<tech_name>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*(?:Organiz[^\:]+|Company)(?:[^\:]+)?\:(?P<tech_org>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*(?:Contact\s*)?Email(?:[^\:]+)?\:(?P<tech_email>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*Country(?:[^\:]+)?\:(?P<tech_country>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*(?:State|Province)(?:[^\:]+)?\:(?P<tech_state>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*City(?:[^\:]+)?\:(?P<tech_city>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*(?:Street|Addre)(?:[^\:]+)?\:(?P<tech_street>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*(?:Postal|Post)(?:[^\:]+)?\:(?P<tech_postal>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*Phone(?:[^\:]+)?\:(?P<tech_phone>[^\n]+) | |
| | (?:Tech(?:[^\:]+)?)\s*Fax(?:[^\:]+)?\:(?P<tech_fax>[^\n]+) | |
| # icann report url | |
| | URL\s+of(?:\s+the)?\s+ICANN[^\:]+\:\s*(?P<icann_report_url>https?\:\/\/[^\n]+) | |
| ~xisx', | |
| $resultString, | |
| $match | |
| ); | |
| if (!empty($match)) { | |
| // filtering result | |
| $match = array_filter($match, function($key) { | |
| return ! is_int($key); | |
| }, ARRAY_FILTER_USE_KEY); | |
| $match = array_map(function($v) { | |
| $v = array_filter($v); | |
| return array_map('trim', array_values($v)); | |
| }, $match); | |
| } | |
| // print_r($match); // all data | |
| // $nameServer = $match['name_server']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment