How can I get client side information using either Javascript or Java Servlets?
Client side information such as client's computer name, its IP Address etc.
Thanks in advance.
How can I get client side information using either Javascript or Java Servlets?
Client side information such as client's computer name, its IP Address etc.
Thanks in advance.
You can get some information from the HTTP request headers in a servlet, such as the user-agent (so that you knows which browser the client is using (or want to let us think it is using)) and the remote-addr (the client's IP address (or the proxy's one if the client is using it)).
String userAgent = request.getHeader("user-agent"); // Browser identifier.
String remoteAddr = request.getRemoteAddr(); // IP address.
You can't access system environment variables using Javascript. That would be a security hole. There are ways using ActiveX, but that works only on a certain webbrowser developed by a team in Redmond and still then, the client would need to lower its security settings to allow it to run. That's a big no-no.
The only way to get the computer name is to run a client application which is served by a webpage and let this client application sniff it and send it to the server side. For example a Java Applet using respectively System.getProperty("COMPUTERNAME")
and java.net.URL
. You however need to sign it, else it will prompt a security warning as well.
Get user IP through JS
var ip = '<!--#echo var="REMOTE_ADDR"-->';
Although I'm not sure on the computer name, I presume it would have to involve ActiveX. It use to be possible via ActivexObject in IE. Unsure if its possible anymore, highly doubt it because its not secure in the slightest.