Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why can't I find REMOTE_HOST?

Posted on 1999-06-29
7
Medium Priority
?
193 Views
Last Modified: 2013-12-25
Hello,

I am using a perl cgi to try and get the environment variable REMOTE_HOST.... but nothing is returned? I can get REMOTE_ADDR fine....

Under what conditions is REMOTE_HOST returned/not returned by the client?

Thanks!
Keith
0
Comment
Question by:keithedward
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 5

Expert Comment

by:thoellri
ID: 1834825
Pretty much depends on the server-software you're running. I guess REMOTE_HOST and/or REMOTE_ADDR are filled in by the web-server. For the old Apache I had running on my system (the one which did name-lookups by default) I had REMOTE_HOST in the environment. When I told Apache (in the configuration files) not to do name-lookups any more, I only had REMOTE_ADDR in the environment.

Anyway, replace the $ENV{REMOTE_HOST} with something like:

use Socket;

sub remoteHostname {
  my($name) = $ENV{'REMOTE_HOST'};
  return $name if (defined($name));
  $name = $ENV{'REMOTE_ADDR'};
  return undef if (!defined($name));
  return gethostbyaddr(inet_aton($name));
}

Hope this helps
  Tobias
0
 
LVL 11

Expert Comment

by:mouatts
ID: 1834826
It tends to depend on the web server (and the client) if the client is from a machine that doesn't have a publically accessible host name then some web servers such as IIS will substitute the IP address but others will not create it at all.
0
 
LVL 8

Expert Comment

by:jhurst
ID: 1834827
They are both wrong, it is actually the connection and ISP that are the problem.  The REMOTE_HOST is not sent by default and is only sent when requested so your request is either not being accepted or the request is taking long enough that the thing is timing out.

The bottom line is that you can not rely on being able to get it, which is I guess what you wanted to know.

0
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 
LVL 5

Expert Comment

by:thoellri
ID: 1834828
jhurst,

I hate it if somebody tells me I'm wrong without knowing it better. If you had worked on Apache source code you would know what I'm talking about. I suggest you take a look at src/util_script.c and the function ap_ad_common_vars() for apache 1.3.4. If you still think I'm wrong, post another message. Otherwise cut the crap ok?

Tobias
0
 

Author Comment

by:keithedward
ID: 1834829
sorry, but I think  thoellri gave the better answer.....if he posts a proposed answer I will accept....

I am using the latest Apache server with mod_ssl and mod_perl.....

Keith
0
 
LVL 5

Accepted Solution

by:
thoellri earned 150 total points
ID: 1834830
You're welcome Keith,

Pretty much depends on the server-software you're running. I guess REMOTE_HOST and/or REMOTE_ADDR are filled in by the web-server. For the old Apache I had running on my system (the one which did name-lookups by default) I had REMOTE_HOST in the environment. When I told Apache (in the configuration files) not to do name-lookups any more, I only had REMOTE_ADDR in the environment.

Anyway, replace the $ENV{REMOTE_HOST} with something like:

      use Socket;

      sub remoteHostname {
        my($name) = $ENV{'REMOTE_HOST'};
        return $name if (defined($name));
        $name = $ENV{'REMOTE_ADDR'};
        return undef if (!defined($name));
        return gethostbyaddr(inet_aton($name));
      }

Hope this helps
    Tobias

0
 
LVL 11

Expert Comment

by:mouatts
ID: 1834831
theollri: Totally agree with you.


Steve
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question