# Get the subnet mask

**URL:** <https://www.ruby-forum.com/t/get-the-subnet-mask/79820>\
**Category:** Ruby\
**Created:** [December 19, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/get-the-subnet-mask/79820 "2006-12-19T14:16:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [December 19, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/get-the-subnet-mask/79820/1 "2006-12-19T14:16:23Z")

</div>

Hi,

Is there another way of getting my subnet mask without parsing  
ipconfig/ifconfig ?

David.

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [December 20, 2006, 7:16pm UTC](https://www.ruby-forum.com/t/get-the-subnet-mask/79820/2 "2006-12-20T19:16:31Z")

</div>

David C. wrote:

> Hi,
> 
> Is there another way of getting my subnet mask without parsing  
> ipconfig/ifconfig ?
> 
> David.

There’s IPAddr#mask, from the ‘ipaddr’ library (part of the stdlib).  
Does that help?

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [December 20, 2006, 7:20pm UTC](https://www.ruby-forum.com/t/get-the-subnet-mask/79820/3 "2006-12-20T19:20:43Z")

</div>

On 12/19/06, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> Is there another way of getting my subnet mask without parsing  
> ipconfig/ifconfig ?
> 
> David.

On linux, look somewhere in the /proc

On windows there’s some WINAPI for sure, but it could be PITA to go  
through all the structures. Or try WMI (through Win32OLE) – have look  
at msdn.

It depends on your needs, but parsing ipconfig is the easiest way (be  
sure to take care of localisation, we had problems when we moved from  
english to, say italian windows.)

You can guess the netmask from the address class, but most probably  
that won’t work.

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/get-the-subnet-mask/79820/4 "2007-01-19T16:30:18Z")

</div>

Daniel B. wrote:

> There’s IPAddr#mask, from the ‘ipaddr’ library (part of the stdlib).  
> Does that help?
> 
> Regards,
> 
> Dan

IPAddr#mask can’t meet this requirement I think.  
If the methods for these kinds of requirements (e.g., to get Subnet  
Mask, Ip Addr of the local machine) are not available for now, should we  
provide them in the near future?
