tcl - How to find the Highest IP of given Two -


can tell me how find highest ip address show output has 2 ip address values. please . tried below, other better option.

set ip1 "10.2.244.255" set ip2 "10.2.33.224"  set ip1 [split $ip1 .]  set ip2 [split $ip2 .]  foreach $ip1 j $ip2 {       if { $i > $j} {          puts "ip1 greater" break      } elseif { $i < $j } {          puts "ip2 greater" break      } elseif { $i == $j } {          continue      } } 

one option use -dictionary option of [lsort] right thing numbers in strings:

lsort -dictionary {10.2.244.255 10.2.33.224} 

sorts ip addresses smallest largest. result last number in list.

you can encapsulate in function:

proc larger_ip {a b} {     return [lindex [lsort -dictionary [list $a $b]] end] } 

Comments