Get IP of domain with JavaScript

11,171

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.

Share:
11,171
jorjap
Author by

jorjap

I am an employed student that does freelancing in spare time.

Updated on June 07, 2022

Comments

  • jorjap
    jorjap almost 2 years

    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?

  • jorjap
    jorjap about 13 years
    I thought about that, but I have some problems with cross-domain requests in IE7 and below.
  • xil3
    xil3 about 13 years
    @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?
  • jorjap
    jorjap about 13 years
    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
    jorjap about 13 years
    I don't want to mix any java in this project. Thanks anyway for the suggest. =
  • David Tang
    David Tang about 13 years
    @jorjap, then just use the domain name? Not that this is a very secure way of protecting your scripts anyway.
  • xil3
    xil3 about 13 years
    @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.