-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbindconf2csv.py
More file actions
executable file
·64 lines (48 loc) · 1.39 KB
/
Copy pathbindconf2csv.py
File metadata and controls
executable file
·64 lines (48 loc) · 1.39 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
'''
Tool to parse a bind9 zone conf file to csv
Usage:
cat bind9_zone.conf | python bindconf2csv.py
Author: Rafael Alpizar Lopez
Version: 1.0
Change Log:
2017-12-27 - First version
'''
import pandas as pd
import sys
import re
zones = list()
def process_zones():
read_zone = True
lines = sys.stdin.readlines()
for line in lines:
#print("Line "+line)
if line.find('zone') > -1:
zone = dict()
try:
zone['name'] = re.match('zone "(.*)".*', line).group(1)
except:
read_zone = False
print('Line "{}" could not be parsed.'.format(line))
else:
read_zone = True
elif line.find('}', 0, 1) > -1:
# print(zone)
zones.append(zone)
read_zone = False
if read_zone:
zone_data = re.match('\s*([\-\w]+)*\s(.*)', line)
try:
key = zone_data.group(1)
value = zone_data.group(2)
zone[key] = value
except Exception as e:
print('Error in line '+line)
print(e)
# print('{}, {}'.format(key, value))
pd.DataFrame(data=zones).to_excel('/tmp/bindzone.xlsx', sheet_name='Bind Zones')
return 0
def main():
test = process_zones()
if __name__ == '__main__':
main()