You are viewing a single comment's thread. Return to all comments →
perl
use capture groups to test that IPv4 digits are valid
while(<>){ chomp; next if $. == 1; if (/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/){ ($1 < 256 && $2 < 256 && $3 < 256 && $4 < 256) ? print "IPv4\n" : print "Neither\n"; } elsif ( /^([a-f\d]{1,4}):([a-f\d]{1,4}):([a-f\d]{1,4}):([a-f\d]{1,4}):([a-f\d]{1,4}):([a-f\d]{1,4}):([a-f\d]{1,4}):([a-f\d]{1,4})$/ ){ print "IPv6\n"; } else { print "Neither\n"; }
Seems like cookies are disabled on this browser, please enable them to open this website
IP Address Validation
You are viewing a single comment's thread. Return to all comments →
perl
use capture groups to test that IPv4 digits are valid