{gethostbyaddr:ip}

Description

Returns the host name for an IP address by doing a reverse-DNS (PTR) lookup, the AA counterpart of the PHP gethostbyaddr function. Pass an IPv4 or IPv6 address; the command returns the registered host name, or the address itself when no PTR record exists. An empty argument returns an empty string and skips the lookup. Because the result comes from live DNS it can change over time and is not cached as a fixed value. Typical use is resolving the visitor's address from the server REMOTE_ADDR variable.

Parameters

ip required default (empty string)

The IP address to resolve, as IPv4 (e.g. 203.0.113.7) or IPv6. The value is passed straight to the system reverse-DNS resolver. An empty value makes the command return an empty string without doing a lookup.

Examples

virtual{gethostbyaddr:8.8.8.8}
Expected(the PTR hostname for 8.8.8.8, e.g. dns.google)
Actualdns.google
Looks up the hostname registered for an IP address through reverse DNS. The result depends on live DNS records and can change over time, so it is not a fixed value. 8.8.8.8 is Google Public DNS.
test[{gethostbyaddr:}]
Expected[]
Actual[]
With no IP, the command does nothing and returns an empty string (the engine short-circuits before calling the system resolver, so no lookup happens). The square brackets are not part of the command; they only make the empty result visible.
test[{gethostbyaddr:0.0.0.1}]
Expected[0.0.0.1]
Actual[0.0.0.1]
When the IP is valid but has no reverse-DNS (PTR) record, the system resolver returns the address itself, so the command echoes the IP back. 0.0.0.1 is in the reserved this-network range and has no PTR record, which makes this output stable.
virtual{gethostbyaddr:{server:REMOTE_ADDR}}
Expected(the visitor's hostname, or their IP if no PTR record exists)
Actual216.73.217.87
The canonical use: resolve the hostname of the visitor making the request. The server REMOTE_ADDR getter supplies the caller's IP; gethostbyaddr turns it into a hostname when a PTR record exists, otherwise the IP is returned. Output varies per visitor, so this is illustrative, not a fixed test.