• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

server from which page accessed

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can I find out from which server my page was accessed? So, if someone logs in from server 23.44.11.9, I want to capture this IP address.
thanks,
Alex
 
mounika paruchuri
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,

I did not exactly understand your question but if you mean you want to know the server IP that answered the request then you can get it through 'request.getServerName()'.This method is in the interface ServletRequest.If not this and you want to find the Client IP then you can get it through 'request.getRemoteAddr()'. Hope this is of any help.
Mounika.
 
Mark Bensing
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use ServletRequest.getRemoteAddr(). From the API documentation:

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

Mark
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys. I also found this one: request.getRemoteHost().toString(); Is this the same as 'request.getServerName()?
 
Mark Bensing
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to my reading of the API documentation, getServerName() will return the name of the server that is running your servlet and getRemoteHost() returns the name of the client machine that issued the request. Note that getRemoteHost is not guaranteed to return a host name... it may return the same value as getRemoteAddr() if the host name of the client machine is not resolved by the servlet container.
I hope this helps,
Mark
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic