Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select concat(inet_ntoa(ip_addr),'-',
- inet_ntoa(ip_addr+(POWER(2,32)-ip_mask-1))) range
- from subnets
- order by ip_addr
- CREATE TABLE cidr (
- bits INT UNSIGNED PRIMARY KEY,
- mask INT UNSIGNED NOT NULL
- );
- INSERT INTO cidr (bits) VALUES
- ( 1), ( 2), ( 3), ( 4), ( 5), ( 6), ( 7), ( 8), ( 9), (10),
- (11), (12), (13), (14), (15), (16), (17), (18), (19), (20),
- (21), (22), (23), (24), (25), (26), (27), (28), (29), (30),
- (31), (32);
- UPDATE cidr SET mask = ((POWER(2,32)-1)<<(32-bits)) & (POWER(2,32)-1);
- SELECT CONCAT(s.ip_addr, '/', c.bits)
- FROM cidr c JOIN subnets s ON (c.mask = inet_aton(s.ip_mask));
- select CONCAT(INET_NTOA(ip_addr),'/',32-log2((4294967296-ip_mask))) net
- from subnets
- order by ip_addr
Add Comment
Please, Sign In to add comment