top of page

Write a script to increment the given ip by 1

if ip is 10.10.10.10  then output should be 10.10.10.11

if 10.10.10.255 than output should be 10.10.11.0


set ip "10.255.10.255"
set list [split $ip "."]
set ww [lindex $list 0]
set xx [lindex $list 1]
set yy [lindex $list 2]
set zz [lindex $list 3]

if {$zz>254} {
set zz 0
incr yy
if {$yy>255} {
set yy 0
incr xx
if {$xx>255} {
set xx 0
incr ww }
if {$ww>255} {
set ww 0
}}} else {
incr zz
}
puts "$ww.$xx.$yy.$zz"

© 2015 Thirumurugan

bottom of page