|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Any one can tell me if it is possible to get IP address of a particular site using its name ie-www.rediffmail.com and it will return IP address on client side in javascript.
|
|
#2
|
||||
|
||||
|
I do'nt think it's possible using Javascript alone.
You might be best using a server side script for that. Out of curiousity, why would you need to do that?
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#3
|
||||
|
||||
|
you could you javascript but it may not be the real ip, you could use...
var ip = '<!--#echo var="REMOTE_ADDR"-->'; hope this helped colton22 |
|
#4
|
||||
|
||||
|
I guess that would mean breaking out of the sandbox, so it should not be possible. You could go for a server-side script in combination with an ajax call (like MCD said).
__________________
Current project: roborally |
|
#5
|
||||
|
||||
|
there is a way to do it in a java applet, but oveously this involves java which some people dont have enabled, i found it on a site when i searched for ip address look up, i couldnt find the code though, only the working model.
colton22 ps i dont know how the code would go, but i do know how i would access the page that contains it. |
|
#6
|
||||
|
||||
|
There are a couple of websites that provide DNS lookup services. I'm not sure if any of them support Java calls though. Perhaps in conjunction with a hidden form, but now you're talking about workarounds.
|
|
#7
|
|||
|
|||
|
Here are some simple example scripts that will lookup a domain name submitted via an HTML form, using a server sided PHP script.
Name the files as suggested in the comments, and place all three of them in the same directory. Code:
<html>
<!--
FILENAME: dnslookup.html
This file's name isn't important, however.
-->
<head>
<title>DNS Check</title>
<script language="javascript" src="dnscheck.js"></script>
</head>
<body>
<table width="0%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right">DOMAIN:</td>
<td align="left"><input type="text" id="domainTxt" name="domainTxt"></td>
<td align="left"><span id="output" class="inputFormError"></span></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" id="submitBtn" value="Submit" onclick="dnsCheck('domainTxt','output')"></td>
</tr>
</table>
</body>
</html>
Code:
//Javascript DNS Lookup
//FILENAME: dnscheck.js
//06-02-2007
//Eli Moulton
var serverData = false;
if (window.XMLHttpRequest)
{
serverData = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
serverData = new ActiveXObject("Microsoft.XMLHTTP");
}
function dnsCheck(inputId,outputId)
{
var outputElem = document.getElementById(outputId);
var inputElem = document.getElementById(inputId);
var lookupResults;
if (serverData)
{
serverData.open('GET','dnscheck.php?domain=' + inputElem.value);
serverData.onreadystatechange = function()
{
if (serverData.readyState == 4 && serverData.status == 200)
{
lookupResults = serverData.responseText;
if (lookupResults == -150)
{
outputElem.innerHTML = "No Domain Given";
}
else if (lookupResults == -100)
{
outputElem.innerHTML = "Lookup Failed/Invalid Domain";
}
else
{
outputElem.innerHTML = "IP: " + lookupResults;
}
}
}
serverData.send(null);
}
else
{
outputElem.innerHTML = "Failed To Create XMLHttpRequest Object";
}
}
Code:
<?php
//DNSCheck server script for use with dnscheck.js
//FILENAME: dnscheck.php
//06-02-2007
//Eli Moulton
if ($_GET['domain'])
{
$lookupData = dns_get_record($_GET['domain'],DNS_A);
if ($lookupData)
{
echo $lookupData[0]['ip'];
}
else
echo -100;
}
else
{
echo -150;
}
?>
I hope you find this helpful. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Dns lookup using javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|