Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



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

Answer / pvrreddy2889

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

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

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

Post New Answer

More Tcl Interview Questions

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

5 Answers   Cisco, HCL,


how to write a startup script in winrunner

0 Answers   Power Grid, Pyxis,


if i give in numbers output should be in characters example : set a 23 o/p twentythree

1 Answers   Alcatel,


how to increment eacl element in a list ? eg: incrlist {1 2 3} =>2 3 4

9 Answers   Honeywell,


How increment a character? For example, I give 'a' and I should get 'b'.

3 Answers  


How do you check whether a string is palindrome or not using TCL script?

10 Answers  


1.What are the different ways to initialize a variable. How to differentiate global and local variables, explain it through a simple tcl program. 2.Create a list of week days and print the first and last character of each day using foreach command 3.Can you write a small program to verify the given input is file or directory.Before checking, just ensure that the file/dir exists or not in the given path. If the given input is a file, findout the size and verify that the file has all read ,write and execute permission.

3 Answers   ATTO, HCL,


Problems with utf-8 between Mac and PC

1 Answers  


How TCL works

1 Answers   Cisco,


Where can find the sample tcl programs?

3 Answers  


write a program to the given ip is valid private address or not(192.168.1.1)?

4 Answers   HCL,


How do you find the length of a string without using string length command in TCL??

6 Answers   Hexaware,


Categories