how to get the Ip and Port number of the server using servlets

hi
how to get the IP address and port number of the Server using servlets.i'm using tomcat 4.0.1 on linux 7.1. i need to get this IP and port. i tried InetAddress but its giving me the clients IP. its urgent.
regards
snehal
snehalkgandhiAsked:
Who is Participating?
 
skg_bfnConnect With a Mentor Commented:
hi
u can use
request.getRequestURL() (returns a String Buffer)
request.getServerName()
request.getSceheme()- returns whether it is "http" or "https" or "ftp"
request.getServerPort() - returns the port number

try this out

regards
SKG
0
 
objectsCommented:
> i tried InetAddress but its giving me the clients IP.

WHere were you running your code?
0
 
snehalkgandhiAuthor Commented:
i just tried it out in my system. and the tomcat is also running on my system. and when i tried it from another system i was getting that particular's systems default IP address
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
CEHJCommented:
request.getHeader("host") should return the info you want
0
 
Igor BazarnyCommented:
Did you try InetAddress.getLocalHost()?
0
 
MoondancerCommented:
0
 
shyamkumarreddyCommented:
snehalkgandhi

Pls use HTML Headers to fetch the Server IPAddress.

Shyam
0
 
snehalkgandhiAuthor Commented:
thanks
SKG
 it was working perfectly.

Snehal
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.