-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdns_entries.py
More file actions
executable file
·42 lines (36 loc) · 1.33 KB
/
dns_entries.py
File metadata and controls
executable file
·42 lines (36 loc) · 1.33 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
#!/usr/bin/python3
import pyeapi
import argparse
import ssl
import ipaddress
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
# Find the home directory where the .eap.conf file is located
from os.path import expanduser
home = expanduser("~")
hosts = []
n = 1
hosts_file = open("hosts", 'a+')
# read in the contents of the eapi.conf file and build a list of all the hostnames in a list called 'hosts'
with open(home + "/.eapi.conf", "r") as file_object:
line = file_object.readline()
while line:
if "connection" in line:
hostname = line.lstrip('[connection:')
hostname = hostname.rstrip(']\n\r')
hosts.append(hostname)
line = file_object.readline()
else:
line = file_object.readline()
for x in hosts:
switch = pyeapi.connect_to(x)
command = switch.enable("show ip interface brief")
for key in command[0]['result']['interfaces'].keys():
hosts_file.write("ip host " + x + "-" + key + " " + command[0]['result']['interfaces'][key]['interfaceAddress']['ipAddr']['address'] + "\n")
hosts_file.close()