我是来自MS DHCP服务器的文本格式的DHCP转储文件。我需要从DHCP池中减去排除IP地址并创建新范围而不排除IP。
Dhcp Server \ PTLISWSA002.prg-dc.xyz.com范围2.10.28.0添加iprange 2.10.28.1 2.10.29.254两种
Dhcp Server \ PTLISWSA002.prg-dc.xyz.com范围2.10.28.0添加 excluderange 2.10.28.1 2.10.28.20
Dhcp Server \ PTLISWSA002.prg-dc.xyz.com范围2.10.28.0添加 excluderange 2.10.28.246 2.10.28.254
Dhcp Server \ PTLISWSA002.prg-dc.xyz.com范围2.10.28.0添加 excluderange 2.10.28.231 2.10.28.233
Dhcp Server \ PTLISWSA002.prg-dc.xyz.com范围2.10.28.0添加 excluderange 2.10.29.1 2.10.29.20
Dhcp Server \ PTLISWSA002.prg-dc.xyz.com范围2.10.28.0添加 excluderange 2.10.29.231 2.10.29.233
Dhcp Server \ PTLISWSA002.prg-dc.xyz.com范围2.10.28.0添加 excluderange 2.10.29.246 2.10.29.254
import csv
from netaddr import *
with open(input_file_name, 'r') as f:
data = []
count_line = 0
for line in f:
if 'iprange' in line:
count_line +=1 # Counting total number of line with "iprange"
field = line.split()
start_ip = field[7]
end_ip = field[8]
dhcp_range = list(iter_iprange(start_ip, end_ip))
with open(input_file_name, 'r') as f:
for line in f:
if 'excluderange' in line:
get_ex_add = line.split()
start_ex_add = get_ex_add[7]
end_ex_add = get_ex_add[-1]
dhcp_exc_range = list(IPSet(IPRange(start_ex_add, end_ex_add)).iter_ipranges())
final_result = (dhcp_range - dhcp_exc_range)
在扣除IP /单IP的排除范围后,需要创建新的DHCP池范围。例如:DHCP池范围192.168.1.1 - 192.168.1.254,排除范围192.168.1.150 - 192.168.1.160,192.168.1.200,192.168.1.250。
预期输出:新池范围 - 192.168.1.1 - 192.168.1.149,192.168.1.161 - 192.168.1.199,192.168.1.201 - 192.168.1.249,192.168.1.251 - 192.168.1.254。< / p>
有人可以帮助我吗?