K
kj
How can script find the hostname (or at least the IP address) of
the host it is running on?
TIA,
kj
the host it is running on?
TIA,
kj
How can script find the hostname (or at least the IP address) of
the host it is running on?
kj said:How can script find the hostname (or at least the IP address) of
the host it is running on?
In <[email protected]> kj <[email protected]>
writes:
Sorry, I shouldn't have written "hostname"; what I want is the full
hostname+domainname combination, as in foo.bar.com (as opposed to
just foo).
Also, I should have mentioned that I looked at the Perl FAQ, but
didn't get a satisfactory answer to my question.
The same way you'd do it in any other language: read the environment
variables.
kj said:How can script find the hostname (or at least the IP address) of
the host it is running on?
TIA,
kj
KKramsch said:^^^^^^^^
^^^^^^^^^^^^
What makes you think there is an environment variable that has the
domainname info? When I run a script on my Linux box that prints
all of %ENV, not a single %ENV value shows the machine's domain
name.
The OP has not stated anywhere that this is a CGI script.Matt said:What does the domain name have to do with the question as he presented it?
print $ENV{SERVER_NAME};
or if you're on IIS using asp
$Request->ServerVariables("server_name")
kj said:Sorry, I shouldn't have written "hostname"; what I want is the full
hostname+domainname combination, as in foo.bar.com (as opposed to
just foo).
Also, I should have mentioned that I looked at the Perl FAQ, but
didn't get a satisfactory answer to my question. The Perl FAQ does
include a question on how to get the "hostname/domainname/IP
address", but it doesn't really answer the question of how to get
the domainname. It only explains how to get the hostname and the
IP address. It gives advice on how to get the name of the local
DNS server, but says nothing on how that script would use this
information to obtain the host's domainname.
Matt Garrish said:print $ENV{SERVER_NAME};
or if you're on IIS using asp
Tad McClellan said:Perl is not CGI.
CGI is not Perl.
I never would have guessed...
I read the OP's poor first attempt at a question as a stealth cgi question.
If I'm wrong on that account; I'm wrong. However, contrary to the followup
reply, there most definitely *is* an environment variable *in the cgi
environment* to find the hostname. Clearer?
However, contrary to the followup reply, there most definitely *is*
an environment variable *in the cgi environment*
to find the hostname.
Alan J. Flavell said:OK, as the thread has drifted to a stealth CGI discussion (regardless
that the original question almost certainly wasn't)...
You're talking about the host where the CGI script is running, rather
than the address of the client or proxy that's making the request,
right?
This of course is nothing specific to Perl. But, for the convenience
of Perl users, FAQ9 refers, and points to the relevant CGI resources.
I'd have to recommend looking them up to get the fuller picture.
You're talking about the SERVER_NAME, I take it?
kj said:How can script find the hostname (or at least the IP address) of
the host it is running on?
In said:I still look at the sparsity of the original post and see someone who wants
to write a (portable) cgi script that doesn't require knowing the server
it's running on in advance. As I said, if I'm wrong, I'm wrong. I had to
correct the poster who claimed that such a thing does not exist, though.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.