Given a CIDR, how can I convert it to a subnet mask.
A:
Same way you do in any other language
set n 24
set mask [expr {~ 0 << ( 32 - $n )}]
format "%d.%d.%d.%d" [expr {$mask >> 24 & 255}] [expr {$mask >> 16 & 255}] [expr {$mask >> 8 & 255}] [expr {$mask & 255}]
ephemient
2009-11-15 16:27:29
Thanks. What does set mask line actually do ?
2009-11-15 16:46:17
It creates a mask of "bits" that get shifted around, truly working with the data as a bitmask.
Nerdling
2009-11-15 16:57:56
Related to this question, How can I add 1 to an IP address (Example: 192.168.1.0). I have an IP address and a Subnet mask and I am trying to get the first valid IP address in the range. If I do a logical AND between IP and Subnet, I get the subnet number. I need to add 1 to the subnet number to get the first IP.
2009-11-15 17:09:32