Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtain local IP of users machine 1

Status
Not open for further replies.

siberian

Programmer
Sep 27, 2003
1,295
US
Is there a JS function to obtain the IP of the users local machine? The external gateway that the webserver gets is not sufficient for users that are behind NAT.

Thanks
 
This is vbscript, but it still works. Not sure how to do it in javascript.
Code:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
dim ip
dim host
Set DNS = CreateObject("TCPIP.DNS")
ip = Request.ServerVariables("REMOTE_ADDR")
HostName = DNS.GetHostByIP(ip)
</SCRIPT>

-kaht

banghead.gif
 
Tx, this may work since our primary target is IE Windows users.

Still open to a javascript solution but I'll give this a go for now.

Thanks! Have a star :)

 
Yes, I re-read it and see that once I woke up some more.

The problem here is not 'how do I access the environment' its 'My servers are behind load balancers and firewalls, my clients are behind firewalls'

That renders the environment useless since the server can only 'see' the IP of the external gateway of the client network. Additionally, some load balancers will rewrite the source IP to themselves in certain situations.

So, the need is for a client side java or vb script that can pull the users IP address, pop it into a form element on pageload and get me the info that way.

I'll keep poking around, thanks.
 
Did some research, and some thinkin, and here it is in JSP(JScript Server Pages) [afro]
it needs help though, i tried. [sadeyes]
<%@ Language="JScript" %>
<html>
<head>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
</head>
<body>
<%
function GetHostIP() {
try {
var DNS = new ActiveXObject("TCPIP.DNS");
var ip = Request.ServerVariables("REMOTE_ADDR");
var ClientIP = DNS.GetHostByIP(ip);
var strResult;
}
catch (objError) {

strResult = objError + "\n"
strResult += "returned error: " +
(objError.number & 0xFFFF).toString() + "\n\n";
strResult += objError.description;

}
Response.Write(ClientIP);

}
%>



</body>
</html>
 
another stab [tongue]
Code:
<%@ Language="JScript" %>
<html>
<head>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
</head>
<body>
 <%
 var IP = Request.ServerVariables("REMOTE_ADDR");
try {
var DNS = new ActiveXObject("TCPIP.DNS");
var ClientIP = DNS.GetHostByIP(IP);
 var strResult;    
}  
catch (objError) {  
    
        strResult = objError + "\n"
        strResult += "returned error: " + 
            (objError.number & 0xFFFF).toString() + "\n\n";
        strResult += objError.description;
       
    }
    Response.Write(ClientIP);
    
	%>



</body>
</html>
 
nailed it [2thumbsup]
Code:
<%@ Language="JScript" %>
<html>
<head>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
</head>
<body>
 <%
 var IP = Request.ServerVariables("REMOTE_ADDR");
try {
var DNS = new ActiveXObject("TCPIP.DNS");
var ClientIP = DNS.GetIPByHost(IP);
 var strResult = "";    
}  
catch (objError) {  
    
        strResult += objError + "\n"
        strResult += "returned error: " + 
            (objError.number & 0xFFFF).toString() + "\n\n";
        strResult += objError.description;
		Response.Write(strResult);
    }
    Response.Write(ClientIP);
    
	%>



</body>
</html>
[code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top