Второй день как узнал о Tcl
Необходимо в скрипте expect использующем язык Tcl, разбить ip адрес по октетам и значение каждого из них присвоить переменной.
К примеру set ip 10.20.30.40
чтобы a=10 b=20 c=30 d=40
Благодарю за помощь )
Модератор: Модераторы
set ip "10.20.30.40"
regexp -- {(\d+)\.(\d+)\.(\d+)\.(\d+)} $ip - a b c d
set ip "10.20.30.40"
set ipl [split $ip .]
set a [lindex $ipl 0]
set b [lindex $ipl 1]
set c [lindex $ipl 2]
set d [lindex $ipl 3]
switch $octet2 \
"1..100" "puts $octet1" \
"101,150,200" "puts $octet2" \
"201..254" "puts $octet3" \
"default" "puts $octet4" \
switch 1 \
[expr {$sw>0 && $sw<100}] {puts $octet1} \
[expr {$sw == 101 || $sw == 150 || $sw == 200}] {puts $octet2} \
default {puts $octet4}
regexp -- {(\d+)\.(\d+)\.(\d+)\.(\d+)} $ip - octet1 octet2 octet3 octet4
set vpngw 0
switch $octet2\
"1" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2}\
"2" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2}\
"3" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2}\
"4" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2}\
"5" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2; set vpngw vpn-gw1.mns.ru}\
"6" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2; set vpngw vpn-gw2.mns.ru}\
"7" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2; set vpngw vpn-gw3.mns.ru}\
"8" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2; set vpngw vpn-gw1.mns.ru}\
"9" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2; set vpngw vpn-gw2.mns.ru}\
"10" {set mask 255.255.0.0; set gw $octet1.$octet2.0.2; set vpngw vpn-gw3.mns.ru}\
"20" {set mask 255.255.240.0; set gw $octet1.$octet2.[expr [expr $octet3/16]*16].2}\
"21" {set mask 255.255.240.0; set gw $octet1.$octet2.[expr [expr $octet3/16]*16].2}\
"50" {set mask 255.255.240.0; set gw $octet1.$octet2.[expr [expr $octet3/16]*16].2; set vpngw vpn-gw1.mns.ru}\
"51" {set mask 255.255.240.0; set gw $octet1.$octet2.[expr [expr $octet3/16]*16].2; set vpngw vpn-gw1.mns.ru}\
"70" {switch $octet3\
"228" {set mask 255.255.255.0; set gw $octet1.$octet2.$octet3.1}\
"229" {set mask 255.255.255.224; if "$octet4 <= 30" "set gw $octet1.$octet2.$octet3.1"\
else {if "$octet4 >= 66" "set gw $octet1.$octet2.$octet3.65"\
else "set gw $octet1.$octet2.$octet3.33"}}\
"230" {set mask 255.255.255.192; set gw $octet1.$octet2.$octet3.65}\
"233" {set mask 255.255.255.0; set gw $octet1.$octet2.$octet3.1}\
"238" {set mask 255.255.255.240; set gw $octet1.$octet2.$octet3.1}\
"default" {set mask 255.255.255.252; set gw $octet1.$octet2.$octet3.[expr $octet4-1]}}
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2