How to get the next ip for given ip
ex: 10.10.10.1 -> 10.10.10.2
ex: 10.10.10.255 -> 10.10.11.0

Answer Posted / amarnath

#!/usr/local/bin/expect



set ip 10.20.245.250
set a [split $ip .]
puts $a
set oct1 [lindex $a 0]
set oct2 [lindex $a 1]
set oct3 [lindex $a 2]
set oct4 [lindex $a 3]

for {set i 0} {$i<=4574} {incr i } {
if {$oct4<=255} {
puts [join "$oct1 $oct2 $oct3 $oct4" "."]
incr oct4 }
if {$oct4==256} {
incr oct3
set oct4 0
puts [join "$oct1 $oct2 $oct3 $oct4" "."]
incr oct4 }
if {$oct3==256} {
incr oct2
set oct4 0
incr oct3
set oct3 0
puts [join "$oct1 $oct2 $oct3 $oct4" "."]
incr $oct4
}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Hi all, Is there any certification exams available for TCL and Perl. If so please let me know, my mailid is vpbharathi@gmail.com. Thanks in advance, Bharathi.P

2612