-1

I am trying to get hostname of my windows server using below code:

Socket.getLocalAddress().getCanonicalHostName(); 

It's returning the loopback address. in Java help for getLocalAddress() it is mentioned as

"If there is a security manager set, its checkConnect method is called with the local address and -1 as its arguments to see if the operation is allowed. If the operation is not allowed, the loopback address is returned"

Could anyone tell what is this security manager exactly? how I will get the Exact IP address instead of loopback address?

Nurjan
  • 5,889
  • 5
  • 34
  • 54
Pratik
  • 109
  • 1
  • 5
  • 14

1 Answers1

1

InetAddress.getLocalHost().getHostAddress() should give you the IP address.

This is from java doc.

A security manager is an object that defines a security policy for an application. This policy specifies actions that are unsafe or sensitive. Any actions not allowed by the security policy cause a SecurityException to be thrown. An application can also query its security manager to discover which actions are allowed.

For further information check this SO post.

Community
  • 1
  • 1
seal
  • 1,122
  • 5
  • 19
  • 37
  • For further information check the answer you linked which says almost exactly the opposite of what you claim here. – user207421 Oct 17 '16 at 11:51
  • @EJP accepted answer has detail info like how to handle when there are multiple network interface, etc. but others answer kind of straight forward. – seal Oct 17 '16 at 12:09