Last active
March 17, 2023 21:02
-
-
Save f5-rahm/9117c688f7961ad210197bd54ab0bc1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Source File CSV Contents: | |
10.10.10.10, | |
10.10.10.11,hi there | |
10.10.11.0/24, | |
10.10.12.0/24,/url/path/here | |
10.10.13.0/24, | |
Output File Txt Contents: | |
host 10.10.10.10, | |
host 10.10.10.11 := hi there, | |
network 10.10.11.0/24, | |
network 10.10.12.0/24 := /url/path/here, | |
network 10.10.13.0/24, | |
""" | |
import csv | |
with open('dg_ipaddrs.csv', mode='r', encoding='utf-8-sig') as f: | |
reader = csv.reader(f) | |
ipaddrs = list(reader) | |
f_out = open('dg_formatted.txt', 'w') | |
for addr in ipaddrs: | |
if "/" in addr[0] or "mask" in addr[0] or "prefexlen" in addr[0]: | |
if addr[1] == '': | |
f_out.write(f'network {addr[0]},\n') | |
else: | |
value = addr[1].split('\n')[0] | |
f_out.write(f'network {addr[0]} := {value},\n') | |
else: | |
if addr[1] == '': | |
f_out.write(f'host {addr[0]},\n') | |
else: | |
value = addr[1].split('\n')[0] | |
f_out.write(f'host {addr[0]} := {value},\n') | |
f_out.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment