Find IP address of a website using javascript

Hi Experts,

In one of my project requirement, I need to check the IP address of the domains. I cannot use PHP function to get IP address.

Is there way somethig to find out the ip address from javascript?

Thanks,
Sudhindra
LVL 13
Sudhindra A NAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StingRaYCommented:
0
Sam SawalhiIT ConsultantCommented:
0
shobinsunCommented:
May be this would help you:

<html>
<head>
  <script type="text/javascript" src="get_ip.js.php"></script>
</head>
<body onload="displayIP();">
  <div id="usersIP"></div>
</body>
</html>

get_ip.js.php:

function displayIP() {
  document.getElementById('usersIP').innerHTML = "Your IP is <?php echo $_SERVER['REMOTE_ADDR']?>";
}

OR:

http://www.hashemian.com/tools/visitor-IP.htm
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

shobinsunCommented:
Here is another one:

<script type="application/javascript">
    function getip(json){
      alert(json.ip); // alerts the ip address
    }
</script>

<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>
0
Sudhindra A NAuthor Commented:
Hi Experts, thanks for the response..
But I am not interested in the visitor IP address or the client IP address..

Say for example..
I will key in the "www.google.com" in one text box and on click of a button I need the IP address of the google.com (entered site).

Thanks.
0
StingRaYCommented:
It is not possible with only javascript.
0
StingRaYCommented:
Why cannot you use PHP to get the ip by name?
0
shobinsunCommented:
Hi,

We have to use PHP in backend:

<html>
<head>
  <script type="text/javascript" src="get_ip.js.php"></script>
</head>
<body onload="displayIP();">
  <div id="usersIP"></div>
</body>
</html>

get_ip.js.php:

function displayIP() {
  document.getElementById('usersIP').innerHTML = "Your IP is <?php echo gethostbyname('google.com');?>";
}
0
Dave BaldwinFixer of ProblemsCommented:
I use IDServe http://www.grc.com/id/idserve.htm to look up IP addresses from domain names.  Javascript does not have access to do a DNS lookup, you would have to use AJAX to call an external lookup service that would return the IP address to you.  In PHP 5, this will do it: http://us.php.net/manual/en/function.dns-get-record.php  On Windows, you have to have PHP 5.3 or newer.
0
shobinsunCommented:
You can use AJAX for your need:

<script type="application/javascript">
    function getXMLHttp()
    {
      var xmlHttp

      try
      {
        //Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
      }
      catch(e)
      {
        //Internet Explorer
        try
        {
          xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
          try
          {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch(e)
          {
            alert("Your browser does not support AJAX!")
            return false;
          }
        }
      }
      return xmlHttp;
    }
    function MakeRequest()
    {
      var xmlHttp = getXMLHttp();
     
      xmlHttp.onreadystatechange = function()
      {
        if(xmlHttp.readyState == 4)
        {
          HandleResponse(xmlHttp.responseText);
        }
      }
      var namevalue=encodeURIComponent(document.getElementById("ip").value);
      xmlHttp.open("GET", "get_ip.js.php?name="+namevalue, true);
      xmlHttp.send(null);
    }
    function HandleResponse(response)
    {
      document.getElementById('ResponseDiv').innerHTML = response;
    }
</script>
<html>
  <body>
  <input type="text" name="ip" id="ip">
    <input type='button' onclick='MakeRequest();' value='Submit'/>
    <div id='ResponseDiv'>
      This is a div to hold the response.
    </div>
  </body>
</html>

get_ip.js.php:

<?php
echo gethostbyname($_GET['namevalue']);
?>

0
Sudhindra A NAuthor Commented:
Many thanks for responses.

gethostbyname is disbaled by the hosting vendor. So I cannot use that function to get the IP address.
anyway many thanks again..
0
Sudhindra A NAuthor Commented:
I've requested that this question be deleted for the following reason:

It requires server side coding for finding IP. From client side its not possible.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StingRaYCommented:
I have already told you about this on day 26 of Dec. Is it not an answer?
0
Sudhindra A NAuthor Commented:
I was also aware of that but still wanted to check with other so that there may exists any tricky way to get IP address from client (web browser).
0
StingRaYCommented:
And the reason you request for deleting this post is what I have answered. Moreover, there is no mentioned in your question that you were aware of that.
0
Sudhindra A NAuthor Commented:
My reason and your answer may be the same but it didnt gave me the solution.
0
StingRaYCommented:
Not all questions have solutions but answers. Some questions are not possible to solve, the answers tell so. Is it reasonable to delete such questions when someone tells there is no solution for that?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.