开发者

Get Host Name with Curl using ip

Is there a way to get the host name using CURL, or what is the preferred w开发者_JS百科ay using PHP?


You don't need to do this in curl. Just use the gethostbyaddr function.

echo gethostbyaddr('1.2.3.4');


My suggestion would be to experiment without using cURL.

Try looking at: gethostbyname(); and gethostbyaddr();

Basicly:

  1. Get host IP address by using gethostbyname();
  2. Fetch host name by using gethostbyaddr(); with previously fetched IP address.
$ip = gethostbyname('www.example.com');
$host = gethostbyaddr($ip);

echo $host;

Just tested it, and — works, plus, you don't have to know targeted host's IP address.


http://php.net/manual/en/function.gethostbyaddr.php


I don't think you need cURL for this. gethostbyaddr does a reverse DNS lookup. I believe that's what you want.


Could also be gotten with $_SERVER, specifically $_SERVER['HTTP_HOST']

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜