forked from ChrisTruncer/PenTestScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPSorter.py
More file actions
executable file
·38 lines (31 loc) · 1.14 KB
/
IPSorter.py
File metadata and controls
executable file
·38 lines (31 loc) · 1.14 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
#!/usr/bin/env python
# IP sort and uniquing script by @ChrisTruncer
import os
import sys
try:
# Take filename as first argument
ip_file = sys.argv[1]
except IndexError:
# Clear the console
os.system('clear')
print "#####################################################################"
print "# IP Sorter #"
print "#####################################################################\n"
print "[*] ERROR: Please provide a file containing IPs to be uniqued \
and sorted!\n".replace(' ', '')
print "Example: ./IPSorter.py ips.txt"
sys.exit()
# Read in all IPs from user specified file
with open(ip_file, 'r') as open_file:
ips = open_file.readlines()
# Convert to a set to remove duplicates, then convert to list
ips = list(set(ips))
# This came from http://www.secnetix.de/olli/Python/tricks.hawk#sortips
for i in range(len(ips)):
ips[i] = "%3s.%3s.%3s.%3s" % tuple(ips[i].split("."))
# Use built in sort method
ips.sort()
# Replace all the spaces in our list
for i in range(len(ips)):
ips[i] = ips[i].replace(" ", "")
print ips[i].strip()