in reply to Remote HostName using CGI

Returns either the remote host name or IP address. if the former is unavailable:

$cgi->remote_host()

By the way, there's also

$cgi->remote_user()

as an alternative to $ENV{USER_NAME}. In both case, $cgi is a CGI object.