[Mimedefang] RE: What to do w/ SPAM? (ip address regex)
    David F. Skoll 
    dfs at roaringpenguin.com
       
    Mon Sep 23 15:47:01 EDT 2002
    
    
  
On Mon, 23 Sep 2002 perlrtst at ml1.net wrote:
> The following regexp is slower and will make your code a bit harder to 
> read, but it will only mactch valid ipv4 addresses:
> /^(0?0?\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(0?0?\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(0?0?\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(0?0?\d|[01]?\d\d|2[0-4]\d|25[0-5])$/
This is overly-paranoid.  $RelayAddr comes from Sendmail, which gets
it from the getpeername() system call.  If you can't trust that, then
you have bigger problems than a permissive regular expression. :-)
Hovever, it might be worth adding some Perl functions which check if
an address is within a network.  For example:
   if (address_in_network($RelayAddr, "192.168.128.0/25")) {
	#...
   }
could be a useful thing to do.  (Actually, I bet there's a CPAN module
out there that already does this. :-))
--
David.
    
    
More information about the MIMEDefang
mailing list