|
@ -1,170 +1,81 @@ |
|
|
<?php |
|
|
<?php |
|
|
|
|
|
|
|
|
class whoisQueryEntry { |
|
|
class whoisQuery { // Whois查询 |
|
|
public function getWhois($domain) { |
|
|
private function whois($content, $host = '') { // 执行Whois查询 |
|
|
$temp = explode('.', $domain); |
|
|
$cmd = $GLOBALS['env']['WHOIS_TOOL'] . ' ' . $content; |
|
|
$tld = $temp[count($temp) - 1]; |
|
|
if ($host != '') { |
|
|
$servers = array( |
|
|
$cmd .= ' -h ' . $host; |
|
|
"com" => "whois.verisign-grs.com", |
|
|
} |
|
|
"net" => "whois.verisign-grs.com", |
|
|
return shell_exec($cmd); |
|
|
"org" => "whois.pir.org", |
|
|
} |
|
|
"info" => "whois.afilias.info", |
|
|
|
|
|
"biz" => "whois.neulevel.biz", |
|
|
private function formatParam($param) { // 格式化输入参数 |
|
|
"us" => "whois.nic.us", |
|
|
if (strtoupper(substr($param, 0, 2)) === 'AS') { |
|
|
"uk" => "whois.nic.uk", |
|
|
$asNum = substr($param, 2 - strlen($param)); |
|
|
"ca" => "whois.cira.ca", |
|
|
if (is_numeric($asNum)) { return 'AS' . $asNum; } // AS + 纯数字 |
|
|
"tel" => "whois.nic.tel", |
|
|
} |
|
|
"ie" => "whois.iedr.ie", |
|
|
if (filter_var($param, FILTER_VALIDATE_IP)) { // IP地址 |
|
|
"it" => "whois.nic.it", |
|
|
if(filter_var($param, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { // IPv6地址 |
|
|
"li" => "whois.nic.li", |
|
|
$param = (new DNS)->zipIPv6($param); // 格式化IPv6地址 |
|
|
"no" => "whois.norid.no", |
|
|
} |
|
|
"cc" => "whois.nic.cc", |
|
|
return $param; // IPv4 / IPv6 |
|
|
"eu" => "whois.eu", |
|
|
} |
|
|
"nu" => "whois.nic.nu", |
|
|
$info = (new Domain)->analyse($param); |
|
|
"au" => "whois.aunic.net", |
|
|
if (isset($info['site'])) { // 请求参数识别到有效域名 |
|
|
"de" => "whois.denic.de", |
|
|
return $info['site']; |
|
|
"ws" => "whois.worldsite.ws", |
|
|
} |
|
|
"sc" => "whois2.afilias-grs.net", |
|
|
return null; |
|
|
"mobi" => "whois.dotmobiregistry.net", |
|
|
} |
|
|
"pro" => "whois.registrypro.pro", |
|
|
|
|
|
"edu" => "whois.educause.net", |
|
|
private function getWhoisInfo($param) { // 发起whois查询 输入 AS+编号 / IP地址 / 网址 |
|
|
"tv" => "whois.nic.tv", |
|
|
$notFound = array( |
|
|
"travel" => "whois.nic.travel", |
|
|
'No whois server is known for this kind of object.', |
|
|
"name" => "whois.nic.name", |
|
|
'Unknown AS number or IP network. Please upgrade this program.' |
|
|
"in" => "whois.inregistry.net", |
|
|
|
|
|
"me" => "whois.nic.me", |
|
|
|
|
|
"at" => "whois.nic.at", |
|
|
|
|
|
"be" => "whois.dns.be", |
|
|
|
|
|
"cn" => "whois.cnnic.cn", |
|
|
|
|
|
"asia" => "whois.nic.asia", |
|
|
|
|
|
"ru" => "whois.ripn.ru", |
|
|
|
|
|
"ro" => "whois.rotld.ro", |
|
|
|
|
|
"aero" => "whois.aero", |
|
|
|
|
|
"fr" => "whois.nic.fr", |
|
|
|
|
|
"se" => "whois.iis.se", |
|
|
|
|
|
"nl" => "whois.sidn.nl", |
|
|
|
|
|
"nz" => "whois.srs.net.nz", |
|
|
|
|
|
"mx" => "whois.nic.mx", |
|
|
|
|
|
"tw" => "whois.apnic.net", |
|
|
|
|
|
"ch" => "whois.nic.ch", |
|
|
|
|
|
"hk" => "whois.hknic.net.hk", |
|
|
|
|
|
"ac" => "whois.nic.ac", |
|
|
|
|
|
"ae" => "whois.nic.ae", |
|
|
|
|
|
"af" => "whois.nic.af", |
|
|
|
|
|
"ag" => "whois.nic.ag", |
|
|
|
|
|
"al" => "whois.ripe.net", |
|
|
|
|
|
"am" => "whois.amnic.net", |
|
|
|
|
|
"as" => "whois.nic.as", |
|
|
|
|
|
"az" => "whois.ripe.net", |
|
|
|
|
|
"ba" => "whois.ripe.net", |
|
|
|
|
|
"bg" => "whois.register.bg", |
|
|
|
|
|
"bi" => "whois.nic.bi", |
|
|
|
|
|
"bj" => "www.nic.bj", |
|
|
|
|
|
"br" => "whois.nic.br", |
|
|
|
|
|
"bt" => "whois.netnames.net", |
|
|
|
|
|
"by" => "whois.ripe.net", |
|
|
|
|
|
"bz" => "whois.belizenic.bz", |
|
|
|
|
|
"cd" => "whois.nic.cd", |
|
|
|
|
|
"ck" => "whois.nic.ck", |
|
|
|
|
|
"cl" => "nic.cl", |
|
|
|
|
|
"coop" => "whois.nic.coop", |
|
|
|
|
|
"cx" => "whois.nic.cx", |
|
|
|
|
|
"cy" => "whois.ripe.net", |
|
|
|
|
|
"cz" => "whois.nic.cz", |
|
|
|
|
|
"dk" => "whois.dk-hostmaster.dk", |
|
|
|
|
|
"dm" => "whois.nic.cx", |
|
|
|
|
|
"dz" => "whois.ripe.net", |
|
|
|
|
|
"ee" => "whois.eenet.ee", |
|
|
|
|
|
"eg" => "whois.ripe.net", |
|
|
|
|
|
"es" => "whois.ripe.net", |
|
|
|
|
|
"fi" => "whois.ficora.fi", |
|
|
|
|
|
"fo" => "whois.ripe.net", |
|
|
|
|
|
"gb" => "whois.ripe.net", |
|
|
|
|
|
"ge" => "whois.ripe.net", |
|
|
|
|
|
"gl" => "whois.ripe.net", |
|
|
|
|
|
"gm" => "whois.ripe.net", |
|
|
|
|
|
"gov" => "whois.nic.gov", |
|
|
|
|
|
"gr" => "whois.ripe.net", |
|
|
|
|
|
"gs" => "whois.adamsnames.tc", |
|
|
|
|
|
"hm" => "whois.registry.hm", |
|
|
|
|
|
"hn" => "whois2.afilias-grs.net", |
|
|
|
|
|
"hr" => "whois.ripe.net", |
|
|
|
|
|
"hu" => "whois.ripe.net", |
|
|
|
|
|
"il" => "whois.isoc.org.il", |
|
|
|
|
|
"int" => "whois.isi.edu", |
|
|
|
|
|
"iq" => "vrx.net", |
|
|
|
|
|
"ir" => "whois.nic.ir", |
|
|
|
|
|
"is" => "whois.isnic.is", |
|
|
|
|
|
"je" => "whois.je", |
|
|
|
|
|
"jp" => "whois.jprs.jp", |
|
|
|
|
|
"kg" => "whois.domain.kg", |
|
|
|
|
|
"kr" => "whois.nic.or.kr", |
|
|
|
|
|
"la" => "whois2.afilias-grs.net", |
|
|
|
|
|
"lt" => "whois.domreg.lt", |
|
|
|
|
|
"lu" => "whois.restena.lu", |
|
|
|
|
|
"lv" => "whois.nic.lv", |
|
|
|
|
|
"ly" => "whois.lydomains.com", |
|
|
|
|
|
"ma" => "whois.iam.net.ma", |
|
|
|
|
|
"mc" => "whois.ripe.net", |
|
|
|
|
|
"md" => "whois.nic.md", |
|
|
|
|
|
"mil" => "whois.nic.mil", |
|
|
|
|
|
"mk" => "whois.ripe.net", |
|
|
|
|
|
"ms" => "whois.nic.ms", |
|
|
|
|
|
"mt" => "whois.ripe.net", |
|
|
|
|
|
"mu" => "whois.nic.mu", |
|
|
|
|
|
"my" => "whois.mynic.net.my", |
|
|
|
|
|
"nf" => "whois.nic.cx", |
|
|
|
|
|
"pl" => "whois.dns.pl", |
|
|
|
|
|
"pr" => "whois.nic.pr", |
|
|
|
|
|
"pt" => "whois.dns.pt", |
|
|
|
|
|
"sa" => "saudinic.net.sa", |
|
|
|
|
|
"sb" => "whois.nic.net.sb", |
|
|
|
|
|
"sg" => "whois.nic.net.sg", |
|
|
|
|
|
"sh" => "whois.nic.sh", |
|
|
|
|
|
"si" => "whois.arnes.si", |
|
|
|
|
|
"sk" => "whois.sk-nic.sk", |
|
|
|
|
|
"sm" => "whois.ripe.net", |
|
|
|
|
|
"st" => "whois.nic.st", |
|
|
|
|
|
"su" => "whois.ripn.net", |
|
|
|
|
|
"tc" => "whois.adamsnames.tc", |
|
|
|
|
|
"tf" => "whois.nic.tf", |
|
|
|
|
|
"th" => "whois.thnic.net", |
|
|
|
|
|
"tj" => "whois.nic.tj", |
|
|
|
|
|
"tk" => "whois.nic.tk", |
|
|
|
|
|
"tl" => "whois.domains.tl", |
|
|
|
|
|
"tm" => "whois.nic.tm", |
|
|
|
|
|
"tn" => "whois.ripe.net", |
|
|
|
|
|
"to" => "whois.tonic.to", |
|
|
|
|
|
"tp" => "whois.domains.tl", |
|
|
|
|
|
"tr" => "whois.nic.tr", |
|
|
|
|
|
"ua" => "whois.ripe.net", |
|
|
|
|
|
"uy" => "nic.uy", |
|
|
|
|
|
"uz" => "whois.cctld.uz", |
|
|
|
|
|
"va" => "whois.ripe.net", |
|
|
|
|
|
"vc" => "whois2.afilias-grs.net", |
|
|
|
|
|
"ve" => "whois.nic.ve", |
|
|
|
|
|
"vg" => "whois.adamsnames.tc", |
|
|
|
|
|
"yu" => "whois.ripe.net" |
|
|
|
|
|
); |
|
|
); |
|
|
if (!isset($servers[$tld])){ |
|
|
if (strpos($param, 'AS') === 0 || filter_var($param, FILTER_VALIDATE_IP)) { // 请求内容为 AS编号 / IP地址 |
|
|
die('Error: No matching nic server found!'); |
|
|
$content = $this->whois($param); |
|
|
|
|
|
foreach ($notFound as $msg) { // 匹配错误信息 |
|
|
|
|
|
if (trim($content) === $msg) { |
|
|
|
|
|
$content = $this->whois($param, 'whois.iana.org'); // 手动查询IANA服务器 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return array( |
|
|
|
|
|
'param' => $param, |
|
|
|
|
|
'content' => $content |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
$server = $servers[$tld]; |
|
|
$content = $this->whois($param); // 请求内容为域名 |
|
|
$output = ''; |
|
|
if (trim($content) === 'No whois server is known for this kind of object.') { // 无内置whois服务器地址 |
|
|
if ($conn = fsockopen ($server, 43)) { |
|
|
$domain = explode('.', $param); |
|
|
fputs($conn, $domain."\r\n"); |
|
|
$tld = '.' . $domain[count($domain) - 1]; // 获取网址顶级域名 |
|
|
while(!feof($conn)) { |
|
|
$whoisServer = (new Domain)->getWhoisServer($tld); // 获取对应Whois服务器 |
|
|
$output .= fgets($conn, 128); |
|
|
if ($whoisServer == null) { |
|
|
|
|
|
return array( |
|
|
|
|
|
'param' => $domain, |
|
|
|
|
|
'content' => 'TLD currently has no whois server' // 顶级域无Whois服务器 |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
fclose($conn); |
|
|
$content = $this->whois($param, $whoisServer); // 手动向对应服务器查询 |
|
|
} else { |
|
|
|
|
|
die('Error: Could not connect to ' . $server . '!'); |
|
|
|
|
|
} |
|
|
} |
|
|
return $output; |
|
|
return array( |
|
|
|
|
|
'param' => $domain, |
|
|
|
|
|
'content' => $content |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function whoisInfo($param) { // Whois查询接口 带缓存 |
|
|
|
|
|
$param = $this->formatParam($param); |
|
|
|
|
|
if ($param == '') { return null; } // 输入错误 |
|
|
|
|
|
// TODO: redis cache |
|
|
|
|
|
$info = $this->getWhoisInfo($param); // 发起查询 |
|
|
|
|
|
return $info; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class whoisQueryEntry { |
|
|
public function query($rawParam) { |
|
|
public function query($rawParam) { |
|
|
$content = $this->getWhois($rawParam); |
|
|
// TODO: help message / enshort whois info / splite long message |
|
|
|
|
|
$content = (new whoisQuery)->whoisInfo($rawParam)['content']; |
|
|
tgApi::sendMessage(array( |
|
|
tgApi::sendMessage(array( |
|
|
'text' => $content, |
|
|
'text' => $content, |
|
|
'disable_web_page_preview' => 'true' // 不显示页面预览 |
|
|
'disable_web_page_preview' => 'true' // 不显示页面预览 |
|
|