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 an expression or perl script to identify the entered
ip address is valid or not?

Answer Posted / anil

The first reply won't match 192.168.99.99. [0-5] matches
only 0,1,2,3,4,5. How about the other numbers?

Second one is almost correct, but the first octet can't be
'0'. I mean, 0.1.2.3 is not a valid address.

print "Enter an ip address: ";
$ans=<stdin>;
chomp($ans);
if ($ans =~ m/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
{
if ( ($1>0) && ($1<=255) && ($2<=255) && ($3<=255) &&
($4<=255))
{
print "An IP Address";
}
else
{
print "Not an IP Address";
}
}
else
{
print "Not an IP Address";
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you open a file in a write-only mode in perl?

920


How can you replace the characters from a string and save the number of replacements?

865


What is a chop() function in perl?

975


What is the use of "stderr()"?

984


Explain tk?

945


There are some duplicate entries in an array and you want to remove them. How would you do that?

881


How do you turn on the perl warnings?

888


How to close a directory in perl?

896


Explain '->' in perl?

899


What is the use of -w, -t and strict in Perl?

962


What is hash?

999


How do find the length of an array?

1081


How to add elements in a hash in perl?

883


How do you set environment variables in perl?

994


What happens in dereferencing?

990