procmail
[Top] [All Lists]

Re: How to match IP's

2001-09-05 15:47:35
Rick Leir asked,

| Is there an easier way? I would like to be able to just
| put '61.134.3.0 - 61.134.20.95' in a rule.

Regexps are designed to match text strings and not to think about numeric
interpretations.  Yes, you could do this:

  \[61\.134\.(([3-9]|1[0-9])\.[0-9][0-9]?[0-9]?|20\.([1-8]?[0-9]|9[0-5]))]

or whatever I should have typed.  However, this might be easier on the
brain:  After you've extracted an IP address into a variable we'll call IP,

:0
* IP ?? ^^\/[0-9]+
 {
   byte1=$MATCH

   :0
   * $ IP ?? ^^()$byte1\.\/[0-9]+
   {
    byte2=$MATCH

    :0
    * $ IP ?? ^^()$byte1\.$byte2\.\/[0-9]+
    {
     byte3=$MATCH

     :0
     * $ IP ?? ^^()$byte1\.$byte2\.$byte3\.\/[0-9]+
     { byte4=$MATCH }
    }
   }
  }

And thereafter you can use the values separately.  So to see if something is
in the range you named, 61.134.3.0 - 61.134.20.95, this is much easier to
read:

 :0
 * byte1 ?? ^^61^^
 * byte2 ?? ^^134^^
 {
  :0
  * byte3 ?? ^^([3-9]|1[0-9])^^
  { thatrange=yes }
  :0E
  * byte3 ?? ^^20^^
  * byte4 ?? ^^([1-8]?[0-9]|9[0-5])^^
  { thatrange=yes }
 }

And I suppose something could be written to use scoring instead.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>