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

What are the arguements we normally use for perl interpreter?

906


List the prefix dereferencer in Perl.

880


In Perl we can show the warnings using some options in order to reduce or avoid the errors. What are that options?

944


What are the different instances used in cgi overhead?

930


How will you create a file in perl?

918


What is the use of 'ne' operator?

924


How to close a directory in perl?

872


What is hash?

960


How many data types are there in perl?

908


How to convert arrays into a string in perl?

886


Explain lexical variables.

894


Mention the difference between die and exit in Perl?

1042


explain the various functions/directives in perl that allow you to include/import a module. Also, state the differences between them.

813


How can you use Perl warnings and what is the importance to use them?

905


what are steps to do to lock the sony ericsson mobile with password?

2139