-2

I am simply trying to achieve something like this:

function getIp() {
var urlenter = document.getElementById('io');
var IPOUT = urlenter.IpAdress !------HERE!!!!!!!!------!

location.href = IPOUT;
}

so if I typed 'facebook.com' in 'io' it would set the href to the ip adress of facebook.com

PaperCut
  • 1
  • 1
  • 2
  • 1
    It may be simple, but it's not easy. In fact, it's not possible (without a third party service). – cheeken Jan 29 '12 at 15:25
  • 1
    possible duplicate of [Can I lookup the IP address of a hostname from javascript?](http://stackoverflow.com/questions/102605/can-i-lookup-the-ip-address-of-a-hostname-from-javascript) – Paul Sasik Jan 29 '12 at 15:26
  • 1
    you cannot do that "with JavaScript". What you **can** do, is to have IP-table in your javascript, or (better) requesting some server with your script, which will send you back the IP, of the page that script was called from. – c69 Jan 29 '12 at 15:27
  • What your asking isn't that simple. First of all, there is no property on a string in javascript which gives you the IpAddress if the string so happens to be a URL. So far as I know, getting the IP address of the requesting client is possible http://stackoverflow.com/questions/391979/get-client-ip-using-just-javascript. But obtaining the IP of another site might be best done on the server side. – Zoidberg Jan 29 '12 at 15:28

2 Answers2

2

JavaScript doesn't have any concept of hostnames or IP addresses. You would have to use an external service to resolve an IP address from a hostname.

Jimmy Miller
  • 1,327
  • 9
  • 13
0

That's not possible with JavaScript alone.

The resolving between IP addresses and hostnames are handled at the DNS level, which is way before JavaScript ever comes to life. It only gets to know the host it is connected to, whether that is by an actual hostname or an IP address.

Still though, you could have JavaScript connect to an outside service, e.g. your server via Ajax, and have it make the resolving.

Sune Rasmussen
  • 906
  • 4
  • 13