-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipcollate.py
More file actions
40 lines (30 loc) · 725 Bytes
/
ipcollate.py
File metadata and controls
40 lines (30 loc) · 725 Bytes
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
# ipcollate.py
# Strip IP addresses from several files
# and dump to a single file
#
# Author: Reuben Joseph <reubenej@gmail.com>
#
import os
import csv
def list_files(dir):
""" List the files in a directory"""
for subdir, dirs, files in os.walk(dir):
for file in files:
print os.path.join(subdir,file)
return file
def dedup(iplist):
""" Remove duplicates from a list of values """
return list(set(iplist))
def load_file(file):
""" Recieve a file object and dump to file """
iplist = []
try:
fd = open(file, "rb")
except IOError:
print "Error cannot read the file"
else:
reader = csv.reader(fd, delimiter= ' ',)
for row in reader:
iplist.append(row)
fd.close()
return iplist