Last active
October 5, 2016 17:34
-
-
Save mrhampson/35f91c0bcd6d7a2fc73cd4339cd05b20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import sys | |
| import subprocess | |
| def is_valid_ip4(s): | |
| a = s.split('.') | |
| if len(a) != 4: | |
| return False | |
| for x in a: | |
| if not x.isdigit(): | |
| return False | |
| i = int(x) | |
| if i < 0 or i > 255: | |
| return False | |
| return True | |
| def main(): | |
| if len(sys.argv) != 2: | |
| print ('Expected one arguments, the file name with the list of IPs') | |
| sys.exit(1); | |
| ipFileLines = [] | |
| outputSamplicate2055 = [] | |
| outputSamplicate6343 = [] | |
| try: | |
| ipFile = open(sys.argv[1], 'r'); | |
| ipFileLines = ipFile.read().splitlines() | |
| except IOError: | |
| print ('Could not find or open {0} for reading'.format(sys.argv[1])) | |
| sys.exit(1) | |
| lineNumber = 1 | |
| for line in ipFileLines: | |
| # Just dump comments into configs | |
| if len(line.strip()) == 0: | |
| continue | |
| elif len(line) > 0 and line[0] == '#': | |
| outputSamplicate2055.append(line) | |
| outputSamplicate6343.append(line) | |
| elif is_valid_ip4(line.strip()): | |
| outputSamplicate2055.append('0.0.0.0/0.0.0.0: {0}/2055'.format(line.strip())) | |
| outputSamplicate6343.append('0.0.0.0/0.0.0.0: {0}/6343'.format(line.strip())) | |
| else: | |
| print ('Found invlaid IP on line {0}'.format(lineNumber)) | |
| print ('Note: each line must be a comment starting with # or a valid ip4 address') | |
| print ('Only one address per line') | |
| sys.exit(1) | |
| lineNumber += 1 | |
| with open('samplicate2055.list', 'w+') as outfile: | |
| outfile.write('\n'.join(outputSamplicate2055)) | |
| with open('samplicate6343.list', 'w+') as outfile: | |
| outfile.write('\n'.join(outputSamplicate6343)) | |
| subprocess.call(['killall', 'samplicate']) | |
| subprocess.call(['samplicate', '-S', '-p', '2055', '-b', '262144', '-c', 'samplicate2055.list']) | |
| subprocess.call(['samplicate', '-S', '-p', '6343', '-b', '262144', '-c', 'samplicate6343.list']) | |
| print ('Rebooting system . . .') | |
| subprocess.call(['shutdown', '-r', 'now']) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment