开发者

convert CIDR to subnet mask in tcl

开发者 https://www.devze.com 2022-12-11 06:22 出处:网络
Given a CIDR, how can I convert it to a开发者_如何转开发 subnet mask.Same way you do in any other language

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号