Reputation: 34424
i want to get server actual name and ip address in jsp . when i do request.getServerName()
it returns me localhost. But i dont want name as localhost but actual name of machine (like in my case it is IBV-0076). Is there a way i can get Ip address also of server which is processing the request?
When i do request.getLocalAddr() i get address as 0.0.0.0 but my server ip is 10.253.18.76
Upvotes: 0
Views: 7301
Reputation: 870
here is an sample with Servername and IP. It is the IP the server see on its endpoint (maybe different because of NAT) and the serverName the client used and is accessible from the client. ${pageContext.request.localAddr}
Upvotes: 0
Reputation: 337
I would use NetworkInterfaces
to obtain information about servers configured interfaces. See Oracle What Is a NetworkInterface?
Upvotes: 2
Reputation: 1832
This also depends on how you have accessed the server. Please use the acutal server IP address, which is used for accessing the webpage and then check the results. This is because if you use the loopback IP of the server, the interface will be bound to "localhost" host name. This usually happens when you are testing the webapp on the same machine as the server.
Upvotes: 1
Reputation: 1040
For the IP-Address, you can find Methods like getLocalAdrr()
for the Request-Object.
Also, you can check the URL for the Servername with getRequestURL()
.
If you always get 0.0.0.0, please check the Network-Configuration of your Server.
Upvotes: 0