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 / pavithra kumar

proc incri { no ip } {
set ip [split $ip .]
set 4_oct [ lindex $ip 3]
set 3_oct [ lindex $ip 2]
set 2_oct [ lindex $ip 1]
set 1_oct [ lindex $ip 0]


for {set i 0 } { $i < $no } {incr i } {
if {$4_oct <= 254 } {
incr 4_oct

puts [ lreplace $ip 0 3 $1_oct $2_oct $3_oct $4_oct ]
} elseif { $3_oct <=254 } {
set 4_oct 0
incr 3_oct
puts [ lreplace $ip 0 3 $1_oct $2_oct $3_oct $4_oct ]
} elseif { $2_oct <=254 } {
set 4_oct 0
set 3_oct 0
incr 2_oct
puts [ lreplace $ip 0 3 $1_oct $2_oct $3_oct $4_oct ]
} elseif { $1_oct <=254 } {
set 4_oct 0
set 3_oct 0
set 2_oct 0
incr 1_oct
puts [ lreplace $ip 0 3 $1_oct $2_oct $3_oct $4_oct ]
} else { puts " ip is full " }
}
}

Is This Answer Correct ?    2 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