Sudhindra A N
asked on
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
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
Try these two links
http://bytes.com/topic/javascript/answers/92174-finding-ip-address-using-javascript
http://www.javascriptkit.com/script/script2/displayip.shtml
I hope this answers your question!
Thank you,
Sam
http://bytes.com/topic/javascript/answers/92174-finding-ip-address-using-javascript
http://www.javascriptkit.com/script/script2/displayip.shtml
I hope this answers your question!
Thank you,
Sam
May be this would help you:
<html>
<head>
<script type="text/javascript" src="get_ip.js.php"></scri pt>
</head>
<body onload="displayIP();">
<div id="usersIP"></div>
</body>
</html>
get_ip.js.php:
function displayIP() {
document.getElementById('u sersIP').i nnerHTML = "Your IP is <?php echo $_SERVER['REMOTE_ADDR']?>" ;
}
OR:
http://www.hashemian.com/tools/visitor-IP.htm
<html>
<head>
<script type="text/javascript" src="get_ip.js.php"></scri
</head>
<body onload="displayIP();">
<div id="usersIP"></div>
</body>
</html>
get_ip.js.php:
function displayIP() {
document.getElementById('u
}
OR:
http://www.hashemian.com/tools/visitor-IP.htm
Here is another one:
<script type="application/javascri pt">
function getip(json){
alert(json.ip); // alerts the ip address
}
</script>
<script type="application/javascri pt" src="http://jsonip.appspot.com/?callback=getip"></script>
<script type="application/javascri
function getip(json){
alert(json.ip); // alerts the ip address
}
</script>
<script type="application/javascri
ASKER
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why cannot you use PHP to get the ip by name?
Hi,
We have to use PHP in backend:
<html>
<head>
<script type="text/javascript" src="get_ip.js.php"></scri pt>
</head>
<body onload="displayIP();">
<div id="usersIP"></div>
</body>
</html>
get_ip.js.php:
function displayIP() {
document.getElementById('u sersIP').i nnerHTML = "Your IP is <?php echo gethostbyname('google.com' );?>";
}
We have to use PHP in backend:
<html>
<head>
<script type="text/javascript" src="get_ip.js.php"></scri
</head>
<body onload="displayIP();">
<div id="usersIP"></div>
</body>
</html>
get_ip.js.php:
function displayIP() {
document.getElementById('u
}
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.
You can use AJAX for your need:
<script type="application/javascri pt">
function getXMLHttp()
{
var xmlHttp
try
{
//Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
//Internet Explorer
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLH TTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.X MLHTTP");
}
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.res ponseText) ;
}
}
var namevalue=encodeURICompone nt(documen t.getEleme ntById("ip ").value);
xmlHttp.open("GET", "get_ip.js.php?name="+name value, true);
xmlHttp.send(null);
}
function HandleResponse(response)
{
document.getElementById('R esponseDiv ').innerHT ML = 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['namev alue']);
?>
<script type="application/javascri
function getXMLHttp()
{
var xmlHttp
try
{
//Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
//Internet Explorer
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLH
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.X
}
catch(e)
{
alert("Your browser does not support AJAX!")
return false;
}
}
}
return xmlHttp;
}
function MakeRequest()
{
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange
{
if(xmlHttp.readyState == 4)
{
HandleResponse(xmlHttp.res
}
}
var namevalue=encodeURICompone
xmlHttp.open("GET", "get_ip.js.php?name="+name
xmlHttp.send(null);
}
function HandleResponse(response)
{
document.getElementById('R
}
</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['namev
?>
ASKER
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..
gethostbyname is disbaled by the hosting vendor. So I cannot use that function to get the IP address.
anyway many thanks again..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have already told you about this on day 26 of Dec. Is it not an answer?
ASKER
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).
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.
ASKER
My reason and your answer may be the same but it didnt gave me the solution.
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?
http://javascriptsource.com/user-details/ip-address.html