For some reason, about once a day I lose net connection to my PC. Disconnecting the ethernet cable and reconnecting it, or restarting the router restores my net connection. Once I get my dedicated folding rig, I do no want to have to do this as the aim is the folding rig should be a low maintenance 24/7 folding machine.
So I solved my problem by writing a small C# program and a batch script. Just in case anyone else is having the same problem as me, this should help.
C# code:
(urlToCheck and batchFileLoc variables may be changed)
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Diagnostics;
using System.Threading;
namespace TEST_restartRouter
{
class Program
{
static void Main(string[] args)
{
string urlToCheck = @"http:\\www.google.com";
string batchFileLoc = @"c:\batchtest.bat";
Uri urlCheck = new Uri(urlToCheck);
WebRequest request = WebRequest.Create(urlCheck);
request.Timeout = 15000;
WebResponse response;
while (true)
{
try
{
response = request.GetResponse();
}
catch
{
Process proc = new Process();
proc.StartInfo.FileName = batchFileLoc;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
}
Thread.Sleep(600000); //wait 10min
}
}
}
}
Batch file:
(telnet will have to be enabled in router settings
Code:
192.168.1.1
WAIT "login:"
SEND "username\m" //ur username here
WAIT "Password:"
SEND "password\m" //ur password here
WAIT "#"
SEND "reboot\m" //command to reboot modem here
WAIT "#"
SEND "exit\m"
I'm just going to run this on my folding rig. The program runs infinitely, checking for a net connection every ten min, and if the connection is down, it restarts the router.