[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 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:

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

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.