package Regexp::Common::dns; # # $Id: dns.pm,v 1.10 2003/11/19 02:43:46 ctriv Exp $ # use strict; use vars qw($VERSION); $VERSION = '0.00_01'; use Regexp::Common qw/pattern net/; our $DEFAULT_RFC = 'hybrid'; =head1 NAME Regexp::Common::dns - Common DNS Regular Expressions =head1 SYNOPSIS use Regexp::Common qw/dns/; while (<>) { $RE{'dns'}{'data'}{'mx'} and print 'an mx'; $RE{'dns'}{'data'}{'soa'} and print 'a soa'; } if ($host =~ $RE{'dns'}{'domain'}) { print "hostname found'; } =head1 PATTERNS =head2 $RE{'dns'}{'int16'} Matches a 16 bit unsigned integer in base 10 format. =cut # 16 bit unsigned int is 65535 pattern name => [qw(dns int16)], create => '(?k:6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d{1,3}|[0-5]?\d{1,4})' ; =head2 $RE{'dns'}{'int32'} Matches a 32 bit integer in base 10 format. =cut # 32 bit unsigned int is 4294967295 pattern name => [qw(dns int32)], create => '(?k:429496729[0-5]|42949672[0-8]\d|4294967[0-1]\d\d|429496[0-6]\d{1,3}|42949[0-5]\d{1,4}|4294[0-8]\d{1,5}|429[0-3]\d{1,6}|42[0-8]\d{1,7}|4[0-1]\d{1,8}|[0-3]?\d{1,9})' ; =head2 $RE{'dns'}{'domain'} Matches a DNS domain name. By default this regexp uses a pragmatic combination of rfc1035, and rfc2181. This is intended to be in sprit with current DNS operation practices. This hybrid approach is simlar to rfc1035, but allows for underscores, and for underscores and hyphens to begin or end a lable. It also allows for wilcarding. The default rule can be set with the C<$Regexp::Common::dns::DEFAULT_RFC> global, which is not exported by this package. By default this regexp matches a domain name according to the rules of L section 2.3.1: ::= | " " ::=