Page 1 of 2
Clients hostname ussingperl?
Posted: Wed Apr 16, 2003 4:50 am
by Nik
just need to read the hostname of the client in one >line. i need the equivalent for php code:
$host=gethostbyaddr($_SERVER['REMOTE_ADDR']);
Posted: Wed Apr 16, 2003 10:26 am
by volka
what's wrong with the snippet already in the script?
I'm not much of a perl coder but it looks usable.
Posted: Wed Apr 16, 2003 11:13 am
by Nik
Not enough arguments for gethostbyaddr at test.pl line 2, near "])"
Execution of test.pl aborted due to compilation errors.
Posted: Wed Apr 16, 2003 11:36 am
by volka
you still use the
version?
2 is the value of AF_INET and it works fine for me.
Posted: Wed Apr 16, 2003 1:26 pm
by Nik
I tried it, well its not displaying an error but it display at all!
i wonder why.....
any ideas?
Posted: Wed Apr 16, 2003 1:27 pm
by Nik
sorry, what i meant is that it doesnt display anything at all!
Posted: Wed Apr 16, 2003 1:33 pm
by volka
is the value of $ENV{REMOTE_ADDR} valid?
Code: Select all
print $ENV{REMOTE_ADDR};
Posted: Wed Apr 16, 2003 1:36 pm
by Nik
yes it is.
if i run this it dispalys a correct ip address.
but we want the hostname.
Posted: Wed Apr 16, 2003 1:44 pm
by volka
try
Code: Select all
use socket;
#dummy entry
$ENV{'REMOTE_ADDR'} = "217.230.186.71";
$ip = $ENV{'REMOTE_ADDR'};
@numbers = split(/\./, $ip);
$ip_number = pack("C4", @numbers);
($host) = (gethostbyaddr($ip_number, 2))ї0];
print $host;
print "done";
as standalone script.
The output should be pD9E6BA47.dip.t-dialin.net
Posted: Wed Apr 16, 2003 3:24 pm
by Nik
yes in fact it displays what u said
but how can i make it display each visitors hostname?
and all that with hust using one line?
like we do with ip address?
Posted: Wed Apr 16, 2003 4:33 pm
by volka
can't tell you what the fault is.
If this script is working it should also if $ENV{'REMOTE_ADDR'} is set to the client's ip by the browser ..it's a string anyway. Check your script again.
"217.230.186.71" simply was my current ip

Posted: Thu Apr 17, 2003 5:14 am
by Nik
well this $ENV{'REMOTE_ADDR'} works ok and gives me the ip address
but isnt there something equivalent for it like
ENV{'REMOTE_HOST'}
how am i gonan do it?
p.s. I dont understand why i dont get mail notification of replies!
Posted: Thu Apr 17, 2003 7:34 am
by volka
I just installed mod_perl (omg, I really did

) and the code snippet is working well (unless I use
localhost in the url, strange)
Maybe mail notification for posts is disabled, don't know
Posted: Thu Apr 17, 2003 7:53 am
by Nik
cool! but what about me how am i gonna get the hostname?
Posted: Thu Apr 17, 2003 8:07 am
by volka
probably the same way

There's no magic in the script.
did you check the error.log? Maybe an error occured (forgot to add
use socket; ?)