I think this is a pretty good IP sanity check snippet. If anyone has any comments please let me know!
use strict; { package IPSanity; use Socket; sub VerifyIP { chomp ($_); my ($a,$c,$d,$e,$f,$g); my $b = 0; if ($_ =~ /[a-zA-Z]+/) { print "$_\n"; $_ = gethostbyname($_); ($c,$d,$e,$f) = unpack('C4', $_); $_ = $c . "." . $d . "." . $e . "." . $f; } my @_temp = split(/\./,$_); $g = $#_temp; undef $_; if ($g ne '3') { print "Your IP address is malformed. I hope this isn't a +reflection of the user...\n"; exit; } foreach $a(@_temp) { if ($a =~ /\b\d\b|\b\d\d\b|\b\d\d\d\b/) { if ($a >= 0 && $a <= 255) { $_ = $_ . int($a); $_ = $_ . "." unless ($b > 2); $b++; } } } my $_IP = inet_aton( $_ ); length($_IP) or die "Sorry, '$_' is invalid.\n"; $_IP = inet_ntoa($_IP); print "$_IP is valid\n"; } } print "IP or Domain Name: "; $_ = <>; chomp; IPSanity->VerifyIP($_);

In reply to IP Sanity Check by jupe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.