transparent block Click here to login or logout The Photo Gallery All about me


Life is an adventure in forgiveness.
Norman Cousins, author and editor (1915-1990)

Tip: Regular expression to match any IP address in FoxyProxy

Posted in Delusions,Ideas,Personal by Riskable on the September 17th, 2008

I’m posting this because I know someone out there will find it useful (or at the very least, a time saver).

What is FoxyProxy?

FoxyProxy is a great add-on to Firefox that lets you define multiple rule-based proxy servers.  It lets you do things like define a rule that loads all URLs through a certain proxy server except those that match a given pattern.  Rules can be wildcards (*whatever.com*) or regular expressions (https?://.*.whatever.com.*).

The problem (need an IP address regex)

I had a problem with FoxyProxy where IP addresses (e.g. 127.0.0.1, 10.0.0.1, etc) were being loaded through my work’s proxy server when they shouldn’t be using a proxy at all.  This is because I had a proxy setup with a “Match all URLs” rule along with a blacklist rule for local URLs (*.myworkintranet.com*).  What I needed was a blacklist rule that would tell FoxyProxy to load all IP addresses directly.  Specifically, I needed a regular expression that would match any IP address.

The solution (regular expression matching any IP address)

https?://[1-9][0-9]?[0-9]?.[0-9][0-9]?[0-9]?.[0-9][0-9]?[0-9]?.[0-9][0-9]?[0-9]?.*

There you have it.  I know this will also match invalid IP addresses (e.g. 999.999.999.999) but it shouldn’t matter since there’s no number-only top-level domains (i.e. .999 as opposed to say, .com).

Also, in case you were wondering FoxyProxy uses the Javascript regular expression format.

Other regular expressions you might find useful

Same thing but for FTP URLs:

ftp://[1-9][0-9]?[0-9]?.[0-9][0-9]?[0-9]?.[0-9][0-9]?[0-9]?.[0-9][0-9]?[0-9]?.*

Match reserved (non-Internet) IP addresses (i.e. 127.X.X.X, 10.X.X.X, 192.168.X.X, and 172.16-31.X.X):

https?://(127|10|172|192)\.(1[6-9]|2[0-9]|3[01])\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?.*