File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes IP Address of Webserver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "IP Address of Webserver " Watch "IP Address of Webserver " New topic
Author

IP Address of Webserver

Kunal Prakash Gandhi
Greenhorn

Joined: Apr 16, 2002
Posts: 11
How do I get the IP Address of Webserver from full url (as shown in the address bar) into my JSP page?
E.g.:-
URL is :- http:\\10.1.2.153\Login\Login.jsp
How Can I Get http:\\10.1.2.153 or 10.1.2.153

With Regards
Kunal
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi,
you can use the following method of javax.servlet.ServletRequest interface.
public java.lang.String getRemoteAddr()
Returns the Internet Protocol (IP) address of the client that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR.
Returns:
a String containing the IP address of the client that sent the request.
Call this method on the implicit ServletRequest object. i.e "request.getRemoteAddr()".
Cheers
NOTE: If the actual client is behind firewall or Proxy Server, you will get the IP Address of Proxy Server.
[ August 19, 2002: Message edited by: L Goundalkar ]

SCJP, SCWCD
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
"kunal",
Thanks for participating here at the Ranch. However, the name you are using does not comply with our naming convention described at http://www.javaranch.com/name.jsp . Please log in with a new name, which meets these requirements.
You can change your name:
here
Thanks.
Sean
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Originally posted by L Goundalkar:
Hi,
you can use the following method of javax.servlet.ServletRequest interface.
public java.lang.String getRemoteAddr()
Returns the Internet Protocol (IP) address of the client that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR.
Returns:
a String containing the IP address of the client that sent the request.
Call this method on the implicit ServletRequest object. i.e "request.getRemoteAddr()".
Cheers
NOTE: If the actual client is behind firewall or Proxy Server, you will get the IP Address of Proxy Server.
[ August 19, 2002: Message edited by: L Goundalkar ]

That is not the address of the server. That is the address of the client that sent the HTTP request. If you want the name of the server which is serving the request, you use the ServletRequest.getServerName() method. Caution, this will return the server name from the URL. For example, if you use
http://123.456.789.000/myUrl
you would get back 123.456.789.000, but if you use
http://myserver.com/myUrl
you would get back myserver.com. Hope this helps.


James Carman, President<br />Carman Consulting, Inc.
Jamal Romero
Greenhorn

Joined: Jun 21, 2001
Posts: 9
Hi,
Here is a small program. You must know the Machine name. On Windows platform: Go to "Network Neighborhood" then "Identification" Tab.


Jamal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IP Address of Webserver