Resolve IP to Hostname using PHP

后端 未结 4 1648
天涯浪人
天涯浪人 2021-01-05 05:30

How can I resolve an IP address to a hostname using PHP?

相关标签:
4条回答
  • 2021-01-05 05:44

    You should give gethostbyaddr() a shot.

    0 讨论(0)
  • 2021-01-05 05:51

    You can use the gethostbyaddr() function.

    $hostname = gethostbyaddr($ipAddress);
    
    0 讨论(0)
  • 2021-01-05 05:51

    Use gethostbyaddr()

    $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
    
    echo $hostname;
    

    You might find that this function can hang for some time when an address is not found - if this becomes a performance issue for you, check this manual comment which details a hand-coded method which supports a timeout.

    0 讨论(0)
  • 2021-01-05 05:56

    gethostbyaddr()

    0 讨论(0)
提交回复
热议问题