Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 1 | from socket import inet_ntoa |
2 | from struct import pack | ||||
3 | |||||
4 | |||||
5 | def calcDottedNetmask(mask): | ||||
6 | bits = 0 | ||||
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 7 | for i in xrange(32 - mask, 32): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 8 | bits |= 1 << i |
9 | packed_value = pack("!I", bits) | ||||
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 10 | addr = inet_ntoa(packed_value) |
11 | return addr |