venkatarami reddy


{ City } bangalore
< Country > india
* Profession * software engineer
User No # 112965
Total Questions Posted # 0
Total Answers Posted # 1

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 2
Users Marked my Answers as Wrong # 1
Questions / { venkatarami reddy }
Questions Answers Category Views Company eMail




Answers / { venkatarami reddy }

Question { 9707 }

Write a proc to increment the ip by the given no. of times.
The incremented IPs should be a valid one.

Ex: proc {ip no_of_incrments} {
body
}


Answer

Thanks jasmin for your valuable script.
small correction for "if" conditions .

proc increment_ip {ip no_of_inc} {
puts "Ip address --- $ip"
for {set inc 1} {$inc<=$no_of_inc} {incr inc} {
set ip_list [split $ip "."]
set oct1 [lindex $ip_list 0]
set oct2 [lindex $ip_list 1]
set oct3 [lindex $ip_list 2]
set oct4 [lindex $ip_list 3]
incr oct4
if {$oct4>255} {
set oct4 0
incr oct3
}
if {$oct3>255} {
set oct3 0
incr oct2
}
if {$oct2>255} {
set oct2 0
incr oct1
}
if {$oct1>255} {
incr oct1 -1
puts "cannot increment ip"
exit
}
set ip $oct1.$oct2.$oct3.$oct4
puts "next ip -- $ip"
}
}

increment_ip 1.1.1.1 10

Is This Answer Correct ?    2 Yes 1 No