cancel
Showing results for 
Search instead for 
Did you mean: 

Scripting question.....

Scripting question.....

Jimmy2
New Contributor
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

blah

else this

blah

end

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

ty

7 REPLIES 7

dflouret
Extreme Employee
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)
endif



dflouret
Extreme Employee
Jimmy,

An EXOS switch can have multiple IP addresses, which one are you interested in? Mgmt vlan, Default vlan?

Drew_C
Valued Contributor III
RegEx is fun 🙂
Take a look at the IP Address examples for TCL on this page: http://wiki.tcl.tk/989
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.

-Drew

Jimmy2
New Contributor
Ok, so I can use regexp for something like this
if deviceip ends in .6 do this
else
do this
end

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
GTM-P2G8KFN