Write a proc to increment the ip by the given no. of times.
The incremented IPs should be a valid one.
Ex: proc <name> {ip no_of_incrments} {
body
}
Answers were Sorted based on User's Feedback
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 |
Answer / jasmin
proc increment_ip {ip no_of_inc} {
puts "ip..... $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 "new ip .... $oct1.$oct2.$oct3.$oct4"
}
increment_ip 10.10.10.1 10
Is This Answer Correct ? | 1 Yes | 3 No |
Where can find the sample tcl programs?
Which scripting language is better among TCL Perl and Python and why?
how to remote log in to a system A to system B ,execute commands in it and collect the log in system A from B using TCL script??
1 Answers Global Edge, Sandvine,
How increment a character? For example, I give 'a' and I should get 'b'.
if i give in numbers output should be in characters example : set a 23 o/p twentythree
how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4
Write a proc to increment the ip by the given no. of times. The incremented IPs should be a valid one. Ex: proc <name> {ip no_of_incrments} { body }
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
Set ip address as 10.30.20.1 write a script to replace the 30 with 40 ?
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
Test case on windows calculator?
{Anu Anudeep Anukumar Amar Amaravathi Aruna} is their any possibility to find the letter "a"in the given list? if yes how?