Clients hostname ussingperl?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Clients hostname ussingperl?

Post 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']);
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what's wrong with the snippet already in the script?
I'm not much of a perl coder but it looks usable.
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

Not enough arguments for gethostbyaddr at test.pl line 2, near "])"
Execution of test.pl aborted due to compilation errors.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you still use the

Code: Select all

gethostbyaddr($ip_number, 2)
version?
2 is the value of AF_INET and it works fine for me.
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

I tried it, well its not displaying an error but it display at all!
i wonder why.....

any ideas?
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

sorry, what i meant is that it doesnt display anything at all!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

is the value of $ENV{REMOTE_ADDR} valid?

Code: Select all

print $ENV{REMOTE_ADDR};
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

yes it is.

if i run this it dispalys a correct ip address.

but we want the hostname.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;)
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post 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!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I just installed mod_perl (omg, I really did :twisted: ) 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
Nik
Forum Contributor
Posts: 138
Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece

Post by Nik »

cool! but what about me how am i gonna get the hostname?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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; ?)
Post Reply