This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

How to obtain node IP to be used as a variable in script.

So I want to be able to get the node IP and use it in the below script where "XX.XX" would be replaced with the middle two octets. (Ex. Node IP 172.24.4.65 would somehow insert 24.4. in the script below where "XX.XX." for every iteration.

I started with this simple script which works:

config t
vlan 224
name WiFi
vlan 248
name VLAN0248
!
ip dhcp excluded-address 172.XX.XX.249
!
default interface TwoGigabitEthernet1/0/43
!
interface TwoGigabitEthernet1/0/43
description AP-01
switchport trunk native vlan 248
switchport mode trunk
no shut
!
default interface TwoGigabitEthernet1/0/44
!
interface TwoGigabitEthernet1/0/44
description AP-02
switchport trunk native vlan 248
switchport mode trunk
no shut
!
default interface GigabitEthernet1/0/29
!
interface GigabitEthernet1/0/29
description firewall-lan2
switchport trunk allowed vlan 76,224,248
switchport mode trunk
!
exit
!
ip dhcp pool WAPS
network 172.XX.XX.248 255.255.255.248
default-router 172.XX.XX.249
dns-server 10.100.12.23 10.100.12.21
lease 2
!
ip route 172.XX.XX.224 255.255.255.240 172.XX.XX.66
ip route 172.XX.XX.248 255.255.255.248 172.XX.XX.66
!
end
wr

But I need to manually change the middle two octets per device:

Is this even possible?  I would appreciate any help, thanks.

Parents Reply
  •  Thanks for the reply!  How would I slice it to only use the middle two octets then?  I've reviewed the link you provided and I don't see anything in regards to using only part of the variable.   Is there any example you could provide? 

Children
  • So the ncm scripting capabilities are not a full language, essentially they can't perform math and string manipulations like that and they can't perform logic in flight, like you can't run a command,  parse the response and then use that result in the script.  The work around that you can do is to pre calculate that sort of thing with an external script and then assign it to a node custom property.   In the past I've done things like create a property called ManagementIP and execute an ncm job that went out and ran show commands that I would need.   Then I used a powershell script that ran later to parse out what I needed and inserted it into the property.  From that point forward I could just call the node property in future ncm script jobs where I needed to reference to individual device management IPs.

    I'll admit it was a bit of an overly complex Rube Goldberg machine but the client insisted they wanted these things to work that way.   Given the choice I'd have just wrote the whole script in powershell, once I was working outside the product there was no reason not to finish the job with the more flexible tool of an actual scripting language.