Script para ver si el parámetro es “all” o una IP específica. Es un script expect, se puede usar para consultar peticiones a equipos de red de una IP específica y de todo.
#!/bin/expect -f
set timeout 10
#Dont show any output from programs
log_user 0
if {[llength $argv] != 1} {
send_user "Exactly 1 argument expected. Valid argments: IP or all. IP means only connection to that IP, all means print all the session table of firewall"
send_user "Example: scriptname 10.1.60.52\n"
send_user "Example: scriptname all\n"
exit 1
}
set destinationIp [lindex $argv 0];
proc isValidIp {string} {
if {[scan $string %d.%d.%d.%d a b c d] == 4
&& 0 <= $a && $a <= 255 && 0 <= $b && $b <= 255
&& 0 <= $c && $c <= 255 && 0 <= $d && $d <= 255} {
return 1
} else {
return 0
}
}
set i [isValidIp $destinationIp]
if {$destinationIp eq "all"} {
set destinationIp $destinationIp
} elseif {$i eq 1} {
set destinationIp $destinationIp
} else {
puts "Invalid argument. Valid aregument are IP or all \n";
exit 1
}
send_user "the IP is $destinationIp"