我正在寻找一种通过寻找对等IP的秘密来提取对等IP的方法。
例:
peer 1.2.3.10 {
authentication {
mode pre-shared-secret
pre-shared-secret SecretPasswordA
}
connection-type initiate
ike-group IKE_1.2.3.4
local-address 6.7.8.9
vti {
bind vti64
esp-group ESP_1.2.3.4
}
}
peer 1.2.3.20 {
authentication {
mode pre-shared-secret
pre-shared-secret SecretPasswordB
}
connection-type initiate
ike-group IKE_1.2.3.4
local-address 6.7.8.9
vti {
bind vti64
esp-group ESP_1.2.3.4
}
}
peer 1.2.3.30 {
authentication {
mode pre-shared-secret
pre-shared-secret SecretPasswordC
}
connection-type initiate
ike-group IKE_1.2.3.4
local-address 6.7.8.9
vti {
bind vti64
esp-group ESP_1.2.3.4
}
}
如果我知道SecrePasswordB,我将需要检索对等IP,即1.2.3.20,如果没有找到则为空(或其他易于识别的内容)。
文本来自shell命令,进入变量(即TEXT=$(command_string)
)。
因为我只有一个基本的shell,并且系统上很少有可用基本的linux工具完成的工具。在这里,我被困在找不到解决方案的地方...
如果如问题所示将数据格式化为单独的行,则只需一个简单的shell脚本即可。只需将输入拆分为开头的单词,然后将其余的单词拆分即可。每当读取“对等”行时,请保存IP。如果读取了机密,请打印最新的IP。
getPeerIP:
#!/bin/sh
secret="$1"
while read -r arg1 rest; do
case "$arg1" in
peer)
ip="${rest% *}" # prune everything after first space
;;
pre-shared-secret)
if [ "$rest" = "$secret" ]; then
echo "$ip"
exit # don't bother reading rest of file
fi
;;
esac
done
用法:
command_string | getPeerIP 'Secret Password'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句