-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlookup2.py
More file actions
40 lines (30 loc) · 924 Bytes
/
lookup2.py
File metadata and controls
40 lines (30 loc) · 924 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
# Read lists of hostnames from .csv and identify target subnets for capacity reclaim
# Environment: Python3. Use Anaconda3 for future data capabilities
# Instructions: Run from same directory as input file.
import os
import csv
import socket
import lxml
# import pandas as pd
# Get input file and validate input file
file = input('Type filename "in quotes" and press ENTER: ')
exists = os.path.isfile(file)
print('Filename read as:', file, ' and found is ', exists)
# assert isinstance(exists, object)
iplist = [] # initialize empty list
if exists:
with open(file) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
record = row
try:
ip = socket.gethostbyname(record['Name'])
print(record['Name'], ip)
iplist.append(ip)
except:
print('Name not found:', (record['Name']))
continue
else:
print('File not found')
print("Job complete")
# print("Unsorted IPs", iplist)