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 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

How to run a package in tcl

2 Answers  


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

6 Answers   Hexaware,


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

1 Answers   Alcatel,


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

3 Answers  


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 Swap 30 & 40 in IP address 192.30.40.1 using TCL script?

8 Answers   HCL, ONGC,


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  


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  


What does Tcl stand for?

2 Answers  


Which scripting language is better among TCL Perl and Python and why? 

1 Answers   GE,


Test case on windows calculator?

2 Answers  


Categories