Is there a way that I can get the ip address of a machine in Java? To get the IP address from the machine where my jar file is running?
The best answer is:
InetAddress.getLocalHost().getHostAddress();
(The getLocalHost
method is declared in InetAddress
not Inet4Address
.)
It is also worth nothing that getLocalHost()
does some security checks, so this may not work if your JAR is run in a sandbox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With