Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import time
- import re
- PATTERN = re.compile('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2}$')
- def subnet_to_ip_range(buff):
- if PATTERN.match(buff) == None:
- raise ValueError("Input has non IPv4 subnet line(s)")
- st, sub = buff.split('/')
- st = [int(x, 10) for x in st.split('.')]
- sub = 1<<(32-int(sub, 10))
- tot = 0
- for x in st:
- tot *= 256
- tot += x
- return str(tot)+'-'+str(tot+sub)
- buff = ''
- while True:
- c = sys.stdin.read(1)
- if c == '\n' or c == '':
- buff = buff.strip()
- if len(buff) != 0:
- print subnet_to_ip_range(buff)
- buff = ''
- if c == '':
- break
- buff += c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement