Javascript Problems

He has: 1,380 posts

Joined: Feb 2002

hey...i'm trying to put a javascript inside an html document that displays the persons host and IP address to let them know that they are not doing this stuff in secret...heres what i have (and it doesnt work)

<script language="javascript">
  myaddress=java.net.inetaddress.getlocalhost();
  myaddress2=java.net.inetaddress.getlocalhost();
  host=myaddress.gethostname();
  ip=myaddress2.gethostaddress();
  document.write("Your hostname is: "+host);
  document.write("<br>Your IP address is: "+ip);
&lt;/script&gt;
'

help me out please!

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

I'm not a huge Javascript person, but I do think that you need to declare the variables first??? Not sure though

Anyone else have any ideas?

He has: 1,380 posts

Joined: Feb 2002

i tried the definition of variables...it didnt work

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

define the functions?

I've never tried this with JavaScript, sorry.

http://ipid.shat.net:80/

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

http://sharkysoft.com/tutorials/jsa/content/040.html has what you're looking for, I think.

dk01's picture

He has: 516 posts

Joined: Mar 2002

That looks like it should work but it doesn't for me. I think a perl script would be the only way to get a result almost every time. Using java seems to be very inconsistant.
-dk

He has: 1,380 posts

Joined: Feb 2002

then how would i do it in PERL

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I would personally use either SSI or Php.

For SSI:

http://www.wdvl.com/Authoring/SSI/Intro/cgi.html

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

You must declare using var before the variable names.

e.g.

var myaddress ...

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Hmm... just checked again on Google. Look what I found at http://javascript.internet.com/user-details/hostname.html

Quote:
(works only for Netscape Browsers with Java enabled) If you would like to get your visitors IP Addresses, use this script. Very cool.

I tested the following code in Netscape 4.7 and it worked just fine.

Code from http://www.irt.org/discus/messages/25/236.html

&lt;script LANGUAGE="JavaScript"&gt;
myAddress=java.net.InetAddress.getLocalHost();
myAddress2=java.net.InetAddress.getLocalHost();
host=myAddress.getHostName();
ip=myAddress2.getHostAddress();
document.write("Your host name is "+host);
document.write("<BR>Your IP address is "+ip);
&lt;/script&gt;
'

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Isn't that the exact same code as above and in the Java link?

I think it's better to do it server-side -- more reliable and no client side errors to screw you up.

dk01's picture

He has: 516 posts

Joined: Mar 2002

Yes Perl, Php, or ssi. However you like it and whatever capabilities your server has.
-dk

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Quote:
Isn't that the exact same code as above and in the Java link?

Yes, it looks like it, except for capitalisation of a few characters, and that the first snippet didn't work but the one in the link did. Wink

I agree that server side is the way to go for this.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

darn details! thanks for clarifying! Smiling

nicora's picture

He has: 267 posts

Joined: Nov 2001

I would have to agree, server side scripting would be the best solution... whatever langauge is available

CF = #CGI.remote_host#
In fact I think that REMOTE_HOST would work for almost any langauge, I know it does in asp. I have been wrong before tho Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.