Barfoots
asked on
Need Assistance with TCL regular expression in Script run on Fortigate
We have 65+ Fortigate branch firewalls that all have unique subnets based on their branch number.
The third octet in the IP address is the only difference.
What I want to do is dynamically get the third octet from the internal1 interface and use that as a variable in the rest of the script.
I have borrowed from here which works, however when I change the regexp to only get the 3rd octet rather than the whole ip address the script it fails at the regular expression.
Below is the contents of $query. I have highlighted in bold the data I need.
config system interface
edit "internal1"
set vdom "root"
set ip XXX.XXX.XXX.XXX 255.255.255.0
set allowaccess ping https
set dns-query recursive
set type physical
set description "X"
set alias "X"
next
end
XXXXXX (internal1) #
The third octet in the IP address is the only difference.
What I want to do is dynamically get the third octet from the internal1 interface and use that as a variable in the rest of the script.
I have borrowed from here which works, however when I change the regexp to only get the 3rd octet rather than the whole ip address the script it fails at the regular expression.
#!
puts "Script starts ..."
# Create do_cmd procedure to execute CLI commands
proc do_cmd {cmd} {
puts [exec "$cmd\n" "# " 15]
}
# get internal ip
do_cmd "config system interface"
do_cmd "edit internal1"
set query [exec "show\n" "# "]
#puts $query
set output [split $query "\n"]
#Find branch number and puts $ip
regexp {(?<=10.10.)[0-9]{1,3}} $output ip
do_cmd "end"
do_cmd "$ip"
Below is the contents of $query. I have highlighted in bold the data I need.
config system interface
edit "internal1"
set vdom "root"
set ip XXX.XXX.XXX.XXX 255.255.255.0
set allowaccess ping https
set dns-query recursive
set type physical
set description "X"
set alias "X"
next
end
XXXXXX (internal1) #
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.