使用tcl中的接口名称从sh ip int brief中提取ip地址

时间:2017-02-02 17:52:28

标签: networking tcl expect

我是TCL和Expect的新手。我试图使用接口名称提取特定接口的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

但它没有给我任何答案....有人可以帮助我。

1 个答案:

答案 0 :(得分:1)

您正在尝试提取IP地址?例如,对于需要192.168.2.1的“GigabitEthernet / 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

这里你不需要前瞻。此外,您不希望^字符后面有空格。