这有效:
$connection = fsockopen("whois.iis.se", 43);
fputs($connection, "google.se\r\n");
while (!feof($connection)) {
$data .= fgets($connection, 4096);
}
fclose($connection);
echo nl2br($data);
但这不起作用:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "whois.iis.se");
curl_setopt($ch, CURLOPT_PORT, 43);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "google.se\r\n");
$data = curl_exec($ch);
curl_close($ch);
echo nl2br($data);
这个卷曲功能有什么问题?
答案 0 :(得分:2)
WHOIS service protocol比HTTP早得多,可以追溯到20世纪80年代中期,与它几乎没有任何共同之处。您只能在HTTP类型的连接上使用curl
,而不能在任意服务上使用。
答案 1 :(得分:2)
我知道这已经有一年了但是:接受的答案是不正确的。 cURL实际上确实具有支持Whois协议的功能,但它需要的不仅仅是一个简单的请求。
我不知道PHP的确切翻译,但我认为只需更改选项以支持TELNET,因为这是Whois使用的:
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_TELNET);
最后,一旦收到回复,您可能需要处理推荐,除非您遇到具有实际WhoIs数据的直接Whois服务器。对于示例中的Whois服务器,它应返回mot地址,作为google.se
的响应。
这种支持已经存在很长时间了,我相信甚至在这个问题被提出之前就已经存在了。
更新:
很抱歉,还没有真正使用PHP和PHP的CURL,但得到以下工作。它并不理想,但不确定处理stdin的最佳方法。
$filename = "query.txt";
$fp = fopen($filename, "r");
function readFunc($ch, $fh, $length = false) {
return fread($fh, $length);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "telnet://whois.iis.se:43");
curl_setopt($ch, CURLOPT_PORT, 43);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_NOPROGRESS, TRUE);
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_TELNET);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filename));
curl_setopt($ch, CURLOPT_READFUNCTION, 'readFunc');
curl_setopt($ch, CURLOPT_VERBOSE, TRUE); // Can take this out
$data = curl_exec($ch);
curl_close($ch);
echo nl2br($data);
然后返回:
$ php query.php
* Rebuilt URL to: telnet://whois.iis.se:43/
* Trying 91.226.37.83...
* TCP_NODELAY set
* Connected to whois.iis.se (91.226.37.83) port 43 (#0)
* Closing connection 0
# Copyright (c) 1997- IIS (The Internet Foundation In Sweden).<br />
# All rights reserved.<br />
# The information obtained through searches, or otherwise, is protected<br />
# by the Swedish Copyright Act (1960:729) and international conventions.<br />
# It is also subject to database protection according to the Swedish<br />
# Copyright Act.<br />
# Any use of this material to target advertising or<br />
# similar activities is forbidden and will be prosecuted.<br />
# If any of the information below is transferred to a third<br />
# party, it must be done in its entirety. This server must<br />
# not be used as a backend for a search engine.<br />
# Result of search for registered domain names under<br />
# the .se top level domain.<br />
# This whois printout is printed with UTF-8 encoding.<br />
#<br />
state: active<br />
domain: google.se<br />
holder: mmr8008-53808<br />
admin-c: -<br />
tech-c: -<br />
billing-c: -<br />
created: 2008-10-20<br />
modified: 2016-09-18<br />
expires: 2017-10-20<br />
transferred: 2009-03-06<br />
nserver: ns1.google.com<br />
nserver: ns2.google.com<br />
nserver: ns3.google.com<br />
nserver: ns4.google.com<br />
dnssec: unsigned delegation<br />
status: serverDeleteProhibited<br />
status: serverTransferProhibited<br />
status: serverUpdateProhibited<br />
registrar: MarkMonitor Inc<br />
如果您需要它来处理随机字符串,那么您可以轻松地写入临时文件并使用它来传递给函数。遗憾的是,我没有时间继续深入了解PHP curl选项,以确定哪种选项最适合将数据流式传输到WHOIS服务器。
文件query.txt
中只有google.se
。