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:
- Get host IP address by using
gethostbyname();
- 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']
精彩评论