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

Re: [Sheflug] Regular Expressions for IP Address



On Tue, 2005-02-01 at 15:20 +0000, Seb James wrote:
> On Tue, 2005-02-01 at 11:16 +0000, somecoolpc wrote:
> > 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??
> > 
> > B
> 
> This extended regular expression definitely works:

For a _portion of an IP_ only. Sorry, it's been a while since I wrote
this.. You'll need to mod it a little to cover a full IP addr string
(xxx.yyy.zzz.aaa).

> (^25[0-5]$)|(^2[0-4][0-9]$)|(^[01]?[0-9][0-9]?$)|(^[01]?[0-9][0-9]?[\.]$)

So, it matches "255" "124" "12" "12." "1" "1." and so on, but not "256"
or "345".

> Here it is in use (in a c program, see glibc docs for explanation of how
> you can use regexps in c programs):
> 
> regcomp_return = 
> 	regcomp (ip_regex, 
> 		 "(^25[0-5]$)|(^2[0-4][0-9]$)|(^[01]?[0-9][0-9]?$)|(^[01]?[0-9][0-9]?[\.]$)", 
> 		 REG_EXTENDED);
> 
> regards,
> 
> Seb
> 
-- 
Sebastian James - Embedded Systems.
Hypercube Systems Ltd 'Embedded Linux Solutions'
35 Walkley Crescent Road, Sheffield, S6 5BA
Tel: 0845 4580277  Web: www.hypercubesystems.co.uk

___________________________________________________________________

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

  GNU the choice of a complete generation.