Determining Subnet Mask

asim_shankar
asim_shankar used Ask the Experts™
on
Hi,

Is there a way to determine the subnet mask of the machine in Java code? InetAddress.getLocalHost() gives only the IP address, can I get the subnet too somehow?

If the machine is multi-homed, then can I get a list of ALL (ip,subnet) pairs?

Thanks a tonne,

-- Asim
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hello asim,

via Java and especially the java.net - package you can only access the information of your machine you are allowed to access from the virtual machine. The subnet-mask or other interfaces are not read by the virtual machine.
If you do need this information urgently, you could anyway start a program on your machine which gives you the information via "Runtime.getRuntime().exec(...)".
The programs which will help you here are "ipconfig" on Windows-, "ifconfig" on Unix/Linux- machines.

Hope this helps

jMelch
with jdk 1.4, you can get all ip addresses of local machine, but you still cannot get netmask. exec() or JNI is your friend.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial