使用 tcl 中的接口名称从 sh ip int brief 中提取 ip 地址
extract ip address from sh ip int brief using interface name in tcl
我是 TCL 新手,Expect.I 尝试使用接口名称提取特定接口的 IP 地址。
示例输入:
Interface IP-Address OK? Method Status Protocol
Embedded-Service-Engine0/0 unassigned YES NVRAM administratively down down
GigabitEthernet0/0 unassigned YES NVRAM up up
GigabitEthernet0/0.10 10.1.1.1 YES NVRAM up up
GigabitEthernet0/0.20 20.1.1.2 YES NVRAM up up
GigabitEthernet0/1 192.168.2.1 YES NVRAM up up
GigabitEthernet0/2 192.168.1.1 YES NVRAM up up
我试过了,
regexp -line ^ $interfacename.*?(?=(?:\..*?)?\d{1,}) $temp
但它没有给我任何答案....有人可以帮助我吗。
您正在尝试提取 IP 地址?例如,对于 "GigabitEthernet/1",您需要 192.168.2.1,对吗?
如果是:
% set interfacename GigabitEthernet0/1
GigabitEthernet0/1
% set re "^$interfacename\s+(\[\d.]+)"
^GigabitEthernet0/1\s+([\d.]+)
% regexp -inline -line $re $input
{GigabitEthernet0/1 192.168.2.1} 192.168.2.1
% regexp -line $re $input -> ip
1
% set ip
192.168.2.1
您不需要在这里进行前瞻。此外,您不希望 ^
字符后有 space。
我是 TCL 新手,Expect.I 尝试使用接口名称提取特定接口的 IP 地址。
示例输入:
Interface IP-Address OK? Method Status Protocol
Embedded-Service-Engine0/0 unassigned YES NVRAM administratively down down
GigabitEthernet0/0 unassigned YES NVRAM up up
GigabitEthernet0/0.10 10.1.1.1 YES NVRAM up up
GigabitEthernet0/0.20 20.1.1.2 YES NVRAM up up
GigabitEthernet0/1 192.168.2.1 YES NVRAM up up
GigabitEthernet0/2 192.168.1.1 YES NVRAM up up
我试过了,
regexp -line ^ $interfacename.*?(?=(?:\..*?)?\d{1,}) $temp
但它没有给我任何答案....有人可以帮助我吗。
您正在尝试提取 IP 地址?例如,对于 "GigabitEthernet/1",您需要 192.168.2.1,对吗?
如果是:
% set interfacename GigabitEthernet0/1
GigabitEthernet0/1
% set re "^$interfacename\s+(\[\d.]+)"
^GigabitEthernet0/1\s+([\d.]+)
% regexp -inline -line $re $input
{GigabitEthernet0/1 192.168.2.1} 192.168.2.1
% regexp -line $re $input -> ip
1
% set ip
192.168.2.1
您不需要在这里进行前瞻。此外,您不希望 ^
字符后有 space。