-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmissing_numbers.py
More file actions
executable file
·47 lines (39 loc) · 1.49 KB
/
missing_numbers.py
File metadata and controls
executable file
·47 lines (39 loc) · 1.49 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python2.7
import argparse
import sys
def missing_numbers(num_list, start, end):
original_list = [x for x in range(start, end + 1)]
num_list = set(num_list)
return (list(num_list ^ set(original_list)))
########
# MAIN #
########
if __name__ == '__main__':
desc = 'List missing ports from a list'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-s', '--start',
type=int,
action='store',
help='Starting number (default: 0)',
metavar='N',
default=0)
parser.add_argument('-e', '--end',
type=int,
action='store',
help='Last number (default: 65535)',
metavar='N',
default=65535)
parser.add_argument('file',
nargs='?',
type=argparse.FileType('r'),
action='store',
help='file containing a list of ports split by a newline, otherwise read from STDIN',
metavar='FILE',
default=sys.stdin)
args = parser.parse_args()
try:
ports = [int(line.strip()) for line in args.file if len(line.strip())>0 and line[0] is not '#']
except KeyboardInterrupt:
exit()
ports.sort()
print '\n'.join(str(p) for p in missing_numbers(ports, args.start, args.end))