-
Notifications
You must be signed in to change notification settings - Fork 56
/
get_ips.py
35 lines (28 loc) · 957 Bytes
/
get_ips.py
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
import socket
from tempfile import NamedTemporaryFile
import shutil
import csv
import logging
def get_ips(row):
try:
addrs = list(set([str(i[4][0]) for i in socket.getaddrinfo(row[0], row[1], socket.AF_INET)]))
logging.info(row[0] + ' has ips: ' + ','.join(addrs))
if len(row) == 3:
row.append(addrs)
elif len(row) == 4:
row[3] = addrs
except:
if len(row) == 3:
row.append([])
finally:
return row
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
filename = 'acs_url.csv'
tempfile = NamedTemporaryFile(delete=False)
with open(filename, 'rb') as csvFile, tempfile:
reader = csv.reader(csvFile, delimiter=',', quotechar='"')
writer = csv.writer(tempfile, delimiter=',', quoting=csv.QUOTE_ALL)
for row in reader:
writer.writerow(get_ips(row))
shutil.move(tempfile.name, filename)