利用Python或者PHP查询.TT域名的Whois信息
Python代码如下
from requests_toolbelt import MultipartEncoder
import requests
import re
m = MultipartEncoder(
fields={'name': ('', 'x.tt')}
)
headers = {'Content-Type': m.content_type}
url = 'https://nic.tt/cgi-bin/search.pl'
response = requests.post(url, data=m.to_string(), headers=headers)
pattern = r'<tr><td>(.*?)</td> <td>(.*?)</td></tr>'
matches = re.findall(pattern, response.text, re.DOTALL)
for key, value in matches:
print(f"{key.strip()}: {value.strip()}")
没有支持库就按提示安装好库 复制到 sublimetext 直接运行就行了
PHP代码如下
<?php
$ch = curl_init();
$url = 'https://nic.tt/cgi-bin/search.pl';
$fields = [
'name' => 't.tt'
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
$response = curl_exec($ch);
curl_close($ch);
$pattern = '/<tr><td>(.*?)<\/td> <td>(.*?)<\/td><\/tr>/s';
preg_match_all($pattern, $response, $matches);
$res = '';
for ($i = 0; $i < count($matches[1]); $i++) {
$res .= trim($matches[1][$i]) . ': ' . trim($matches[2][$i]) . "<br>";
}
echo $res;
?>
想要把php的装到whois查询里面去 可以使用这种方式
<?php
function ttWhois($domain) {
$ch = curl_init();
$url = 'https://nic.tt/cgi-bin/search.pl';
$fields = [
'name' => "$domain"
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
$response = curl_exec($ch);
curl_close($ch);
$pattern = '/<tr><td>(.*?)<\/td> <td>(.*?)<\/td><\/tr>/s';
preg_match_all($pattern, $response, $matches);
$res = '';
for ($i = 0; $i < count($matches[1]); $i++) {
$res .= trim($matches[1][$i]) . ': ' . trim($matches[2][$i]) . "<br>";
}
return $res;
}
?>
结束 下课…
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。联系邮箱:[email protected]