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
Post
by Nik » Wed Apr 16, 2003 4:50 am
just need to read the hostname of the client in one >line. i need the equivalent for php code:
$host=gethostbyaddr($_SERVER['REMOTE_ADDR']);
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Apr 16, 2003 10:26 am
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 » Wed Apr 16, 2003 11:13 am
Not enough arguments for gethostbyaddr at test.pl line 2, near "])"
Execution of test.pl aborted due to compilation errors.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Apr 16, 2003 11:36 am
you still use the
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 » Wed Apr 16, 2003 1:26 pm
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 » Wed Apr 16, 2003 1:27 pm
sorry, what i meant is that it doesnt display anything at all!
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Apr 16, 2003 1:33 pm
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 » Wed Apr 16, 2003 1:36 pm
yes it is.
if i run this it dispalys a correct ip address.
but we want the hostname.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Apr 16, 2003 1:44 pm
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 » Wed Apr 16, 2003 3:24 pm
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?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Apr 16, 2003 4:33 pm
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 » Thu Apr 17, 2003 5:14 am
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!
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Apr 17, 2003 7:34 am
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
Nik
Forum Contributor
Posts: 138 Joined: Wed Jan 29, 2003 6:02 pm
Location: Thessaloniki, Greece
Post
by Nik » Thu Apr 17, 2003 7:53 am
cool! but what about me how am i gonna get the hostname?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Apr 17, 2003 8:07 am
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; ?)