Open
Description
I have dhcp_static.conf which has 118 IP assigments and i want to parse with python. This file will be included in dhcpd.conf file.
dhcp_static.conf
host host_0 {
hardware ethernet 18:DB:F2:5E:00:00;
fixed-address 10.12.24.81;
}
host host_1 {
hardware ethernet D4:AE:52:BD:00:00;
fixed-address 10.12.42.1;
}
... (many more) ...
host host_118 {
hardware ethernet DC:A6:32:B7:00:00;
fixed-address 10.12.67.22;
}
assigments.py (my script)
import os, types, iscpy
NAMED_FILE = 'dhcp_static.conf'
named_file = open(NAMED_FILE).read()
# print("named_file:",named_file)
isc_arr = iscpy.ParseISCString(named_file)
print(isc_arr)
Result:
$ python assigments.py
[{'host host_117': {'hardware': 'ethernet 18:DB:F2:5E:00:00', 'fixed-address': '10.12.24.81'}}, {'host host_118': {'hardware': 'ethernet DC:A6:32:B7:00:00', 'fixed-address': '10.12.67.22'}}]
If i uncomment printing named_file then i see whole file. So it means that the problem lies in parser.
Additional info:
$ python --version
Python 3.8.10
$ pip freeze
certifi==2021.10.8
charset-normalizer==2.0.10
idna==3.3
iscpy==1.8
openssh-wrapper==0.4
proxmoxer==1.2.0
requests==2.27.1
urllib3==1.26.8
Metadata
Metadata
Assignees
Labels
No labels