Scripting question.....

Almost done with a script that is modifying settings on sites for standardization. It touches about 3000+ devices, one if statement found online parses the script and XOS devices go one way, Extremeware another. Works great. Now I need to add some conditional statements that will look at the IP and determine if it ends in a certain octet....

So something like

If a device IP ends in X.X.X.6 do this


else this



Unable to find the resources online to accomplish this.....should be just one line. Any input?


7 replies

Userlevel 3
What language have you chosen? Do you use XOS CLI Scripting or something else?
XOS scripting.
Userlevel 3
Jimmy wrote:

XOS scripting.

I reckon, you should use regexp TCL function. I'm not very good in TCL actually, but I recommend you to read Using CLI Scripting part in EXOS Concept Guide. There are some useful examples too.
Jimmy wrote:

XOS scripting.

Ok, so I can use regexp for something like this
if deviceip ends in .6 do this
do this

Problem is I have no idea how to get a regexp to do this. Having never used regular expressions before....., after researching online for 3 hours ,my head is about to explode.
Basically I would like an expression to say
dontcare.dontcare.dontcare.mustendin .6
Userlevel 7
Jimmy wrote:

XOS scripting.

RegEx is fun 🙂
Take a look at the IP Address examples for TCL on this page:
Here's a quick and simple one you could use: ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.6$

It doesn't do any checks to make sure your octets are 0-255, but that doesn't seem necessary in your case since it can't be configured out-of-bounds anyway.

Userlevel 6

An EXOS switch can have multiple IP addresses, which one are you interested in? Mgmt vlan, Default vlan?
Userlevel 6
Here's a simple script that will look for the primary IP address in a vlan and store its four octets and mask in variables a, b, c, d and m.

In includes a check for vlans without configured IP address, but does not check for non-existent vlans...

set var vl $read(Input VLAN name:)
set var cli.out 0
show $vl
set var ip $tcl(split ${cli.out} "\n")
show var ip
set var e $tcl(regexp -nocase {Primary IP} $ip)
if ($e != 0) then
set var ip $tcl(lindex $ip 6)
set var ip $tcl(split $ip ":")
set var ip $tcl(lindex $ip 1)
set var ip $tcl(string trim $ip)
set var ip $tcl(split $ip "./")
set var a $tcl(lindex $ip 0)
set var b $tcl(lindex $ip 1)
set var c $tcl(lindex $ip 2)
set var d $tcl(lindex $ip 3)
set var m $tcl(lindex $ip 4)