使用TCL语法将tr69 get InternetGatewayDevice.LANDevice.1.Hosts.Host.2.MACAddress中的MAC地址取出
时间: 2024-03-11 13:49:17 浏览: 70
在TCL中,同样可以使用正则表达式来匹配MAC地址并取出。下面是一个例子:
```
set str [exec tr69 get InternetGatewayDevice.LANDevice.1.Hosts.Host.2.MACAddress]
set mac [regexp -inline {([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}} $str]
puts $mac
```
注意,这里使用了`exec`命令来执行`tr69 get`命令获取MAC地址。正则表达式`([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}`表示匹配MAC地址,`[0-9a-fA-F]{2}`表示匹配两位十六进制数,`:`表示匹配冒号,最终使用`-inline`参数将匹配到的字符串以列表形式返回,取出第一个元素即为MAC地址。
相关问题
使用TCL语法将tr69 get InternetGatewayDevice.LANDevice.1.Hosts.Host.2.Active中的2取出
使用TCL语法可以通过正则表达式来提取数字2,具体代码如下:
```tcl
set str "InternetGatewayDevice.LANDevice.1.Hosts.Host.2.Active"
set pattern {\d+}
if {[regexp $pattern $str match]} {
set result $match
puts $result
} else {
puts "No match"
}
```
输出结果为:
```
2
```
这样就可以提取出字符串中的数字2了。
使用TCL语法将InternetGatewayDevice.LANDevice.1.Hosts.Host.1.IPAddress 192.168.254.100 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.AddressSource Static InternetGatewayDevice.LANDevice.1.Hosts.Host.1.LeaseTimeRemaining 0 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.MACAddress 28:d2:44:ae:2c:95 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.HostName unknown28d244ae2c95 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.InterfaceType Ethernet InternetGatewayDevice.LANDevice.1.Hosts.Host.1.Layer2Interface InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.4 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.Active 1 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.X_0000C5_LastActive Thu Jan 1 00:20:53 1970 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.IPv6AddressNumberOfEntries 0 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.IPAddress 192.168.254.10 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.AddressSource DHCP InternetGatewayDevice.LANDevice.1.Hosts.Host.2.LeaseTimeRemaining 2591999 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.MACAddress 6c:63:9c:08:24:62 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.HostName x5042-2460 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.InterfaceType 802.11 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.Layer2Interface InternetGatewayDevice.LANDevice.1.WLANConfiguration.8 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.Active 1 InternetGatewayDevice.LANDevice.1.Hosts.Host.3.Active 0 InternetGatewayDevice.LANDevice.1.Hosts.Host.3.AddressSource DHCP中的IP地址192.168.254.10取出
set hosts [list {InternetGatewayDevice.LANDevice.1.Hosts.Host.1.IPAddress 192.168.254.100 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.AddressSource Static InternetGatewayDevice.LANDevice.1.Hosts.Host.1.LeaseTimeRemaining 0 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.MACAddress 28:d2:44:ae:2c:95 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.HostName unknown28d244ae2c95 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.InterfaceType Ethernet InternetGatewayDevice.LANDevice.1.Hosts.Host.1.Layer2Interface InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.4 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.Active 1 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.X_0000C5_LastActive Thu Jan 1 00:20:53 1970 InternetGatewayDevice.LANDevice.1.Hosts.Host.1.IPv6AddressNumberOfEntries 0} {InternetGatewayDevice.LANDevice.1.Hosts.Host.2.IPAddress 192.168.254.10 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.AddressSource DHCP InternetGatewayDevice.LANDevice.1.Hosts.Host.2.LeaseTimeRemaining 2591999 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.MACAddress 6c:63:9c:08:24:62 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.HostName x5042-2460 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.InterfaceType 802.11 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.Layer2Interface InternetGatewayDevice.LANDevice.1.WLANConfiguration.8 InternetGatewayDevice.LANDevice.1.Hosts.Host.2.Active 1} {InternetGatewayDevice.LANDevice.1.Hosts.Host.3.Active 0 InternetGatewayDevice.LANDevice.1.Hosts.Host.3.AddressSource DHCP中的IP地址192.168.254.10取出}]
foreach host $hosts {
if {[lindex [split $host]} 1] == "192.168.254.10"} {
set addressSource [lindex [split $host]} 3]
break
}
}
puts $addressSource ;# 输出 DHCP
阅读全文