I've done something similar - in two different ways:
1. For a while, I had a secondary (Verizon) router that would lock up. It sat behind my rock-solid primary router, so I had a script that passed a command through to one of my local machines that was running X10Commander. The command kicked off a macro to kill power to the router (via an appliance module), wait 30 seconds, and then power it back up (with an extra "on" for good measure). That worked file while I needed it (sometimes several times per week). I've since changed routers, so that method isn't usable anymore.
2. Now that my primary router is the one that has occasional hiccups (thanks, Verizon). Since I can't hit it remotely when it has problems, I'm using a rather old program called X10Ping , which checked for external connectivity (from one of my local machines), and then power-cycles the router (using an appliance module) if it loses the Internet connection for more than a few minutes. It keeps a nice log, and has only been needed a few times - but it is fully automatic.