Given a CIDR, how can I convert it to a开发者_如何转开发 subnet mask.
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}]
Sure it's easy to do in plain Tcl, but you may consider using ip
package from Tcllib for IP addresses transformations as it provides numerous convenience functions that make it easy to almost anything you need to do with IPv4 and IPv6 addresses.
精彩评论