Tuesday 20 September 2005

Batch File to Fix my Internet

The setup of the computers at my flat to access the Internet is like this:

Internet--USB ADSL Modem--Server--Fast Switch--Access Point--Computers
                                             |
                                             |-Computers
Some computers are connected to the server via the router, others by the wireless router. Everything is happy in the networking world, except for one problem.

Sometimes the modem on the server drops the Internet connection, and cannot reconnect. The only way that I could find to fix the problem was to logon to the Server with VNC and restart the computer. Eventually I got sick of doing this (after the second time) and decided to write a batch file to do the job for me (after the millionth time).

The batch file checks every 15s to see if the Internet is still working by pinging Google.com. I did start with Microsoft.com, but they must have some automatic protection, because after about 10min of pinging, all further requests were bounced. If the ping fails consistently after three attempts at the ping command, the computer reboots.

The batch file on the server is like so:

@echo off
set timeouts=
:start
echo Testing Internet Connection...
set timeout=
for /f "tokens=1*" %%r in ( 'ping -n 1 google.com' ) do (
  if "%%r"=="Unknown" (
    set timeout=o
  )
  if "%%r"=="Request" (
    set timeout=o
  )
)

if "!timeout!"=="o" (
  echo Failure
  set timeouts=!timeouts!c
) else (
  echo Success
  set timeouts=
)

if "!timeouts!"=="ccc" (
  echo About to restart computer
  net send vincentp4 The Internet computer is about to restart in 20+10s.
)

choice /Ty,20 Continue? 

if errorlevel 2 goto end

if "!timeouts!"=="ccc" (
  net send vincentp4 The Internet computer is going down now!
  shutdown /r /t:10 "Shutting down to fix Internet!" /c
  echo Command issued
  goto end
)

goto start
:end
This file is stored at "c:\bat\test.bat" the machine has Windows 2000 installed. The bat directory also includes choice.com and shutdown.exe. In my start menu startup folder I have the following batch file:
net send vincentp4 This computer has restarted and the Internet needs to be reconnected.
"C:\Program Files\Alcatel\SpeedTouch USB\STDialUp.exe" /WindowsDial /Entry "Alcatel Speedtouch Connection"
net send vincentp4 The Internet is now connected.
cd c:\battest
Which sends me a message before it dials, and after it dials, then starts test.bat.

If you need any explanation, just leave me a comment and I will elaborate.

Thursday 8 September 2005

Work

I am currently designing an XML language to describe configuration structures and rules to allow our graphical package here at Pertronic to manage configurations in a spreadsheet and graphical format. A couple of the things is that the XML file needs to reference data not stored in the file (e.g. strings for display names) as well as define rules and forced actions, which means I need to have some sort of mini scripting language in it.

It is not the easiest thing to do in the world but it is something that needs to be done. I have been building the core of the new package all this year, using C#, and so far I haven't touched on a single UI aspect. I have been defining the way plugins connect, are loaded, and kept from corrupting the programme. As well as an internal logging system, encryption, built in user security, central multi-language interpreter among other core features.

All of these could have been bludged into the different components seperately and I would have made a working product by now. The fact is that I am building it for maximum speed, expandability and mergability.

However, doing it this way, properly planned out and constructed, I am able to reduce the likelyhood of bugs, and with the componentisation that I am also implementing, I am making it easier for bugs to be found it the future. The negative effect of course is time, but I think the benefits will be seen for years to come.

Well, to tell the truth, I have touched on the UI from time to time, with drawings on paper when I was bored. I even went away and made a few controls, which I may make open source when I have finished them (I did them in my own time, and they are therefore mine). They are not the central controls of the package though, just niceties.