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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get Client's IP address?

Status
Not open for further replies.

natncm70

MIS
Jan 16, 2002
66
IN
Hello,
I need to get the Clients machine's IP Address.
I am using JSP/Javascript and JavaBeans. I used Sys_context
option in the oracle.But it is taking only Server machine's IP address. how to take Client's machine's IP address?
What should I do for that?

Regards
 
Try this:

<%@ page contentType=&quot;text/html&quot; %>
<html><head><title>RemoteHost</title></head>
<body>
Remote Address: <%= request.getRemoteAddr() %>
</body>
</html>


 
is it not Client IP Address:<%=request.getRemoteAddress()%>
 
The qualified hostname of the client sending the request can be obtained by using
HostName:<%=request.getRemoteHost()%>
 
Um no. <%=request.getRemoteAddress()%> is invalid syntax and will generate this error:

Method getRemoteAddress() not found in interface javax.servlet.http.HttpServletRequest.
out.print(request.getRemoteAddress());

RTFM
 
As for HostName:<%=request.getRemoteHost()%>, you are more likely to the IP address than the actual Host name. Most machines will not give you that info so freely anymore.
 
Actually it has nothing to do with the host. It has to do with the server and whether to not it performs a reverse DNS lookup for the Hostname.

The other thing you should be aware of when getting a remote address is that 90% of the time the user is going through a proxy or using a NAT address. Thus getting the remote address is only going get that NAT or proxy address not the ACTUAL IP of the machine the the user is browsing from. This is not a problem, it is a reality. On the otherhand you can always use client-side javascript to make the machine cough up the actual IP. This is how Cable and DSL providers typically check to see if you have more than one computer sharing the Cable or DSL line (which is against the EULA for most companies). They get the remote IP in a server-side technology such as ASP or Java and compare it to the IP returned from a client-side DHTML.
 
Yes. Perfectly true. Due to tighter security restrictions, server &quot;machines&quot; will not give your that information so freely anymore.
 
Watching DSL and Cable providers get the IP through a client-side script would be entertaining. JavaScript will not work unless you can guarantee that the majority of the users in the world are using Netscape browsers (they are not). Only Netscape browsers support java.net.InetAddress.getLocalHost().getHostAddress().

There is one more semi-consistant way to get the IP on the client side(regardless of the browser), and that is through a Java Applet. Putting security constraints aside, this would eventually set a form value that would get passed back to the server as you suggest. But, remember, the browser must be Java enabled. Nowadays, many are not.

This is all assuming you could make users navigate to a page that has the script or the app to get the IP. This would not be easy. You do realize that you would have to go to one of the companies pages to load the page, right. Then you would have to get the user to click on a form submit button to send your IP to the server. This will not magically work on its own. You could get JavaScript to auto-submit the form for you onLoad. Still you would have to force all users to use the DSL or Cable providers page as a home page. What a mess.

If DSL and Cable providers are checking your IP with this method as you claim, they are not getting what they want and they have been greatly mislead. This is all interesting though, considering we are at a time when providers DON'T CARE as much as in the past about multiple machines on one line.

Know it instead of repeating what your friends tell you!

RTFM!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top