3

Possible Duplicate:
Can I lookup the IP address of a hostname from javascript?

Can you get the IP address of the current page where the script is running? I can get the current document's domain using var domain = document.domain;. In PhP you can get the IP address of a domain using the function gethostbyname($domain); is there an alternative to this function in JS?

Community
  • 1
  • 1
jorjap
  • 348
  • 3
  • 7
  • 20

3 Answers3

2

Is there an alternative to this function in JS?

Not that I know of.

Your best best would be using Ajax to connect to a PHP or other server-side script that does the lookup for you.

Pekka
  • 418,526
  • 129
  • 929
  • 1,058
  • I thought about that, but I have some problems with cross-domain requests in IE7 and below. – jorjap Feb 09 '11 at 12:04
  • @jorjap Can't you create a script on the same domain and query that? Why are you trying to do cross-domain requests for this? – xil3 Feb 09 '11 at 12:05
  • I'm trying to make some security checks with some js script to prevent the script to be included on unwanted sites. I have the IPs that are the script is allowed to run from but I can't get the IP from the domain where it's run. – jorjap Feb 09 '11 at 12:09
  • @jorjap, then just use the domain name? Not that this is a very secure way of protecting your scripts anyway. – David Tang Feb 09 '11 at 12:40
  • @jorjap I see what you're trying to do now, but unfortunately, there is no sure way to protect your script. If they wanted, they could just view source, copy your script, and run a modified version (without the domain/ip check) on their own server. – xil3 Feb 09 '11 at 14:01
0

Look here: How to find out the server ip address (using javascript) that the browser is connected to?

There's no way to do that in javascript, unless the site was acessed through an IP address, in that case you could look into the host.location property.

Community
  • 1
  • 1
0

if you have knowledge of java applet then you can get IP on the client machine and you can populate the ip in your hidden field and utilize in your javascript

Ankur
  • 101
  • 8