Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IP Address of Webserver

 
Kunal Prakash Gandhi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jamal Romero
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Here is a small program. You must know the Machine name. On Windows platform: Go to "Network Neighborhood" then "Identification" Tab.


Jamal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic