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

Answers were Sorted based on User's Feedback



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

Answer / saravanan6060

#169.254.0.0 through 169.254.255.255




#172.16.0.0 through 172.31.255.255 




#192.168.0.0 through 192.168.255.255

#10.0.0.0 10.255.255.255




set a "10.78.80.2" or 

// a could be any private range the below regexp will match ,if u provide other than private range it will throw an error 

regexp {^(10|169|172|192).([0-9]+|[0-9][0-9]+|1[0-9][0-9]+|2[0-4][0-9]+|25[0-5]+).([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])} $a match 




puts $match

Is This Answer Correct ?    0 Yes 0 No

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

Answer / amarnath

#10.0.0.0 through 10.255.255.255




#169.254.0.0 through 169.254.255.255




#172.16.0.0 through 172.31.255.255




#192.168.0.0 through 192.168.255.255

set ip 192.168.10.1

if {[regexp {^(10|169|172|192).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])} $ip match 1st 2nd 3rd 4th]} {
puts $match
puts "$1st
$2nd
$3rd
$4th" }

Is This Answer Correct ?    0 Yes 0 No

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

Answer / amarnath

#!/usr/local/bin/expect



set ip 172.46.250.200

#### validate private ip add ######

if {[regexp {^(10|169|172|192).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$} $ip match oct1 oct2 oct3 oct4] } {
if {$oct1==10} {
puts "$ip IP is CLASS A private ip range" }
if {$oct1==169} {
if {$oct2==254} {
puts "$ip IP is internal/system private ip range " } else {
puts "$ip is public ip" } }
if {$oct1==192} {
if {$oct2==168} {
puts "$ip IP is CLASS C private ip range " } else {
puts "$ip is public ip"}}
if {$oct1==172} {
if {$oct2>=16} {
#puts "$ip is private ip "
if {$oct2<=31} {
puts "$ip IP is CLASS B private ip range " } else {
puts "$ip is public ip" } } }
} else {

puts "$ip is Invalied ip" }

Is This Answer Correct ?    0 Yes 0 No

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

Answer / saravanan6060

#10.0.0.0 through 10.255.255.255 




#169.254.0.0 through 169.254.255.255




#172.16.0.0 through 172.31.255.255 




#192.168.0.0 through 192.168.255.255




set a "10.78.80.2"
regexp {^(10|169|172|192).([0-9]+|[0-9][0-9]+|1[0-9][0-9]+|2[0-4][0-9]+|25[0-5]+).([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])} $a match i




puts $match

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More Tcl Interview 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

0 Answers  


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,


{Anu Anudeep Anukumar Amar Amaravathi Aruna} is their any possibility to find the letter "a"in the given list? if yes how?

3 Answers   Cisco, HCL,


Write a program to increment IP address to +10 and verify it is correct ip or not ?? example my ip is 172.122.132.143 increment this ip to +10 and verify it is valid ip or not

1 Answers   Alcatel,


how to write a startup script in winrunner

0 Answers   Power Grid, Pyxis,






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 }

2 Answers  


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

9 Answers   Honeywell,


 write a regular expressions to fetch all the valid ip's

3 Answers   Alcatel,


How to extract "information" from "ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb" in tcl using a single command?

12 Answers   Wipro,


Where can find the sample tcl programs?

3 Answers  


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

1 Answers   Alcatel,


how to write the startup scripts in winrunner? can any body explain with example code?

0 Answers  


Categories