write a program to the given ip is valid private address or not(192.168.1.1)?
Answer Posted / 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 |
Post New Answer View All Answers