Usually, there's no need for using a script to ping the server. Just make sure "Check connection time out" is checked under Connect Options. (Did you have this checked?) If your router's TCP timeout is abnormally short, a timer with a short interval could help, or you could see if you can change the TCP timeout on your router's configuration page.
The "Check connection time out" was already checked. The short ping seems to help. I will check my router next though.
Right now I just set up a CTCP Ping from my client to another client I have running but on a different machine. I run a bot client for a channel I help moderate, so the ping I have setup isn't bothering anyone.
Without the ping though, it still will disconnect me if it's let sit for too long. It's kind of odd to me though.