Easy program to recognize local IP addresses within Internet IP addresses doesn't work correctly.
# local addresses are 192.168.x.x 10.x.x.x 127.0.0.1 172.16.x.x
my @addrs = qw(61.177.172.64 110.53.183.252 195.154.47.194
110.53.183.252 190.96.252.188 221.194.47.243 10.1.1.1
100.1.1.1 192.168.0.1 127.0.0.1 172.16.0.1 172.17.0.1 );
$local_ip_match = "m/^192\.168\.|^10\.|^127\.0\.|^172\.16\./";
while (@addrs) {
my $s = shift @addrs;
if ($s =~ $local_ip_match) {
print "got Local IP $s\n";
} else {
print "got Internet IP $s\n";
}
}
Results:
got Internet IP 61.177.172.64
got Internet IP 110.53.183.252
got Internet IP 195.154.47.194
got Internet IP 110.53.183.252
got Internet IP 190.96.252.188
got Internet IP 221.194.47.243
got Local IP 10.1.1.1
YES
got Local IP 100.1.1.1
NO NO - didn't I say 10 followed by a . ??
got Internet IP 192.168.0.1
NO NO - doesn't this match the first part?
got Local IP 127.0.0.1
Right
got Internet IP 172.16.0.1
NO NO -- I thought I had this fingered out?
got Internet IP 172.17.0.1
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.