Whois与fsockopen一起使用而不与curl一起使用 [英] Whois works with fsockopen not with curl

查看:111
本文介绍了Whois与fsockopen一起使用而不与curl一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有效:

$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);

此curl功能有什么问题?

What is wrong with this curl function?

推荐答案

我知道这一岁,但是:接受的答案不正确. cURL实际上确实具有支持Whois协议的功能,但是它比简单的请求花了更多时间.

I know this is a year old but: The accepted answer is incorrect. cURL actually did have functionality to support the Whois protocol but it takes a bit more than a simple request.

我不知道到PHP的确切翻译,但是我认为这只需要更改选项以支持TELNET,因为Whois使用的是

I do not know the exact translation to PHP but I think this would just need options changed to support TELNET since that is what Whois uses:

curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_TELNET);

最后,一旦收到答复,您可能需要处理引荐,除非您要访问具有实际WhoIs数据的直接Whois服务器.对于示例中的Whois服务器,它应该返回mot地址作为google.se的响应.

Finally once you get a response back, you may need to deal with referrals unless you are hitting the direct Whois server that has the actual WhoIs data. For the Whois server in the example it should return mot addresses as as the response for google.se.

这种支持已经存在了很长时间,我相信甚至在问这个问题之前.

This support has been in it for a long time now, I believe even before this question was asked.

更新:

对不起,还没有真正使用PHP和PHP的CURL,但是有以下工作.这不是理想的方法,但不确定处理stdin内容的最佳方法.

Sorry, haven't really worked with PHP much and PHP's CURL but got the following to work. It isn't ideal but wasn't sure best way to handle the stdin stuff.

$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服务器.

If you need it to work for random strings, then you can easily just write to a temporary file and use that to pass into the function. I unfortunately do not have the time to continue digging through the PHP curl options to determine which option may work best for streaming the data to the WHOIS server.

文件query.txt中仅包含google.se.

这篇关于Whois与fsockopen一起使用而不与curl一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆