爱快流控分流,端口分流的设置,编写node.js程序用于批量导入配置

发布时间 2023-03-28 10:50:14作者: 项希盛

客户要求将20个公网IP分配给60个设备使用,每个设备最多使用3个公网IP地址

下面是生成的程序代码

const configTemplate = (id, interface, src_addr) => {
  return `id=${id} enabled=yes comment= type=0 nexthop= interface=${interface} mode=1 src_addr=${src_addr} dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59`;
}

for (let i = 1; i <= 20; i++) {
  const id = i;
  const interface = 'vwan' + i;
  const srcStart = 100 + i * 3 - 2;
  const srcEnd = 100 + i * 3;
  const src_addr = `192.168.1.${srcStart}-192.168.1.${srcEnd}`;
  
  const config = configTemplate(id, interface, src_addr);
  console.log(config);
}

生成结果如下

id=1 enabled=yes comment= type=0 nexthop= interface=vwan1 mode=1 src_addr=192.168.1.101-192.168.1.103 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=2 enabled=yes comment= type=0 nexthop= interface=vwan2 mode=1 src_addr=192.168.1.104-192.168.1.106 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=3 enabled=yes comment= type=0 nexthop= interface=vwan3 mode=1 src_addr=192.168.1.107-192.168.1.109 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=4 enabled=yes comment= type=0 nexthop= interface=vwan4 mode=1 src_addr=192.168.1.110-192.168.1.112 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=5 enabled=yes comment= type=0 nexthop= interface=vwan5 mode=1 src_addr=192.168.1.113-192.168.1.115 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=6 enabled=yes comment= type=0 nexthop= interface=vwan6 mode=1 src_addr=192.168.1.116-192.168.1.118 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=7 enabled=yes comment= type=0 nexthop= interface=vwan7 mode=1 src_addr=192.168.1.119-192.168.1.121 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=8 enabled=yes comment= type=0 nexthop= interface=vwan8 mode=1 src_addr=192.168.1.122-192.168.1.124 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=9 enabled=yes comment= type=0 nexthop= interface=vwan9 mode=1 src_addr=192.168.1.125-192.168.1.127 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=10 enabled=yes comment= type=0 nexthop= interface=vwan10 mode=1 src_addr=192.168.1.128-192.168.1.130 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=11 enabled=yes comment= type=0 nexthop= interface=vwan11 mode=1 src_addr=192.168.1.131-192.168.1.133 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=12 enabled=yes comment= type=0 nexthop= interface=vwan12 mode=1 src_addr=192.168.1.134-192.168.1.136 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=13 enabled=yes comment= type=0 nexthop= interface=vwan13 mode=1 src_addr=192.168.1.137-192.168.1.139 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=14 enabled=yes comment= type=0 nexthop= interface=vwan14 mode=1 src_addr=192.168.1.140-192.168.1.142 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=15 enabled=yes comment= type=0 nexthop= interface=vwan15 mode=1 src_addr=192.168.1.143-192.168.1.145 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=16 enabled=yes comment= type=0 nexthop= interface=vwan16 mode=1 src_addr=192.168.1.146-192.168.1.148 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=17 enabled=yes comment= type=0 nexthop= interface=vwan17 mode=1 src_addr=192.168.1.149-192.168.1.151 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=18 enabled=yes comment= type=0 nexthop= interface=vwan18 mode=1 src_addr=192.168.1.152-192.168.1.154 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=19 enabled=yes comment= type=0 nexthop= interface=vwan19 mode=1 src_addr=192.168.1.155-192.168.1.157 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59
id=20 enabled=yes comment= type=0 nexthop= interface=vwan20 mode=1 src_addr=192.168.1.158-192.168.1.160 dst_addr= protocol=any src_port= dst_port= iface_band=1 week=1234567 time=00:00-23:59

最后直接导入即可