【发布时间】:2021-11-06 03:11:18
【问题描述】:
我有一个名为 vs-hosts-objects.txt 的对象列表,它源自 Cisco ASA 配置。该列表描述了主机名、它们的 IP 地址和它们的 NAT 地址。 示例:
object network net01 subnet 192.168.100.0 255.255.255.0
object network SRV002 host 172.16.0.2
object network SRV003 host 172.16.0.3
object network VPN-Pool range 172.17.100.200 172.17.100.230
object network SRV003 (internal,int-Internet) static 87.88.89.90
object network SRV012 host 172.16.0.12
object network SRV012 (internal,int-Internet) static 87.88.89.91
object network SRV013 host 172.16.0.13
有些附加了 NAT 地址,有些则没有。我需要处理此列表,以便能够将列表导入新防火墙(新供应商)并记录此 IP 用于我们 IPAM 中的主机(因此此时没有子网或范围)。 为此,我需要这样的输出:
SRV003,172.16.0.3,87.88.89.90
SRV012,172.16.0.12,87.88.89.91
SRV013,172.16.0.13
我创建了这个 sn-p,它用于获取具有 NAT 地址的主机:
while read -r line
do
hostobj=`echo $line | grep host | awk '{ print $3 }'`
hostipobj=`echo $line | grep host | awk '{ print $5 }'`
while read -r staticline
do
natobj=`echo $staticline | grep static | awk '{ print $3 }'`
natipobj=`echo $staticline | grep static | awk '{ print $6 }'`
if [ "$natobj" != "" ];
then
if [ "$hostobj" = "$natobj" ];
then
echo "$hostobj,$hostipobj,$natipobj"
fi
fi
done < vs-hosts-objects.txt
done < vs-hosts-objects.txt
但我可以一辈子,不知道如何获取没有附加 NAT 地址的主机,列出。 虽然我确信有更聪明、更好和更快的方法来做到这一点,但我并不反对为没有附加 NAT 的主机运行另一个 sn-p。我所有试图得到这个结果的尝试都以失败告终。 希望得到帮助,祝您生活愉快! 问候
【问题讨论】:
标签: bash while-loop