开发者

Get Host Name with Curl using ip

开发者 https://www.devze.com 2023-01-21 07:04 出处:网络
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.

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

精彩评论

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