[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] Regular Expressions for IP Address



> 
> Hey All,
> 
> I am trying to write a regular expression to ban any ip address, so I
> can put that into my squidGuard ban lists.  But atm I can not get my
> head around how i would do it , without stoping any site that has four
> dots in its name e.g. web.mail.someisp.co.uk
> Any suggestions at all??


I don't use Squid, so I don't know if you need to put ^ and $ round the
following RE to match start and end of line (or address) to do what you want,
but something like this may do it:

	[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+

Where:
	[0-9]+

matches one or more of the digits 0-9 (as opposed to [0-9]* which is zero
or more...), so it's just four of that pattern seperated by dots :-) If the
plus syntax isn't supported, then try this:

	[0-9]\{1,3\}

(the backslashes may not be needed). The curly braces syntax says "match 
between 1 and 3 of the previous pattern", so will match any input that has
1, 2, or 3 digits.

Chris...

-- 
\ Chris Johnson           \
 \ cej [at] nightwolf.org.uk    ~-----,   
  \ http://cej.nightwolf.org.uk/  ~-----------------------------------, 
   \ Redclaw chat - http://redclaw.org.uk - telnet redclaw.org.uk 2000 \____
___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.