Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get the subnet mask?  RSS feed

 
Arun Bommannavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way I can find the subnet mask using Java? We have 255.255.255.0 but in my next dept. they have 255.255.255.192. One way is to tell my users to define it in environment variables, but I was wondering if there is a way to find it programmatically.
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know of any "Pure" java way to get the mask, but you could always query the OS with a System.exec() call. What OS are you using?
Darrin
 
Arun Bommannavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Windows, however, other users of this program run Linux (majority), Solaris (less) and few use Macs. I need to broadcast (no multicast) on a certain UDP port and for this reason I need to get subnet mask.

Could you please explain how to use System.exec() to find the subnet mask?
Thank you.

Arun
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is totally platform dependent, bu the following code will show you the netmask on a Linux machine. Sorry I can't help you with Windows.



Just parse out the mask from the line shown.

Hope that helps!

Darrin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!