Archive for January, 2009

h1

Continuous Ping

31/01/2009

Sometimes when testing network connectivity to a server on the local LAN or a web site I use the ubiquitous PING to do the job.  If I need to do it repeatedly I tend to write a quick DOS batch file (a text based script with a file extension of BAT or CMD).

For example this script would repeatedly ping localhost – the name used for the machine the script is being run on.

@echo off
:START
Ping -n 1 localhost
Goto START

A few years ago I even extended this to include a ping count but it didn’t really add much. I decided it would be more useful to have something that at least gave an indication of how many “good and bad” pings had occurred. At the same time I also found that I wasn’t always necessarily at my computer as I might be tinkering with cables and other networking gear so having some sort of audible cue as to how the pings were going.

I put together the following VB Script to do just this. It hasn’t been tested extensively and I’m sure that there could be a bit more validation. When the script is run it asks for the host to ping and a time at which to stop pinging. It then opens up an Internet Explorer window that displays the information about the pinging.

Option Explicit

'Settings:
'- Number of PC speaker beeps on ping successes/failures
Const BEEPS_ON_PING = 1
Const BEEPS_ON_NO_PING = 3
'- Milliseconds of pause between pings
Const PAUSE_MS = 200
'- Milliseconds pause before automatically closing the progress window
Const AUTO_CLOSE = True
Const FINAL_PAUSE = 5000

'Variable definitions
Dim strHost
Dim dtEnd
Dim objShell, objExplorer
Dim intSuccessfulPingCount, intUnsuccessfulPingCount

'Initialise
Set objExplorer = CreateObject("InternetExplorer.Application")

objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Width = 400
objExplorer.Height = 400
objExplorer.Document.Body.Style.Cursor = "default"
intSuccessfulPingCount = 0
intUnsuccessfulPingCount = 0


'If we don't have a host then ask for one
If Wscript.Arguments.Count < 1 Then
	strHost = InputBox("Please enter the host to ping", "Enter Host", "localhost")
Else
	strHost = Wscript.Arguments(0)
End If

'Double check what we have
If Len(strHost)  0
	'Carry out the ping
	If Ping(strHost, False) = True Then
		'Ping successful
		intSuccessfulPingCount = intSuccessfulPingCount + 1
		Beep(BEEPS_ON_PING)
		WScript.Sleep(PAUSE_MS)
	Else
		'Ping unsuccessful
		intUnsuccessfulPingCount = intUnsuccessfulPingCount + 1
		Beep(BEEPS_ON_NO_PING)
		WScript.Sleep(PAUSE_MS)
	End If
	UpdatePings "<p><b>RUNNING...</b></p>"
Wend

'Finalise
objExplorer.Document.Body.Style.Cursor = "default"
If AUTO_CLOSE Then
	UpdatePings("<p><b>AUTO CLOSING...</b></p>")
	Wscript.Sleep FINAL_PAUSE
	objExplorer.Quit
Else
	UpdatePings("<p><b>PING CYCLE COMPLETED</b></p>")
End If


'Update the display of pings
Sub UpdatePings(p_strSuffix)
	Dim strDisplay

	strDisplay = ""

	strDisplay = strDisplay & "<p>"
	strDisplay = strDisplay & "Finish pinging @ "
	strDisplay = strDisplay & dtEnd
	strDisplay = strDisplay & "<br />"
	strDisplay = strDisplay & "Currently ... "
	strDisplay = strDisplay & Now()
	strDisplay = strDisplay & "</p>"

	strDisplay = strDisplay & "<hr>"

	strDisplay = strDisplay & "<p>"
	strDisplay = strDisplay & "<table border='0'>"
	strDisplay = strDisplay & "<tr>"
	strDisplay = strDisplay & "<td><font color='green'>Successful pings</font></td>"
	strDisplay = strDisplay & "<td><font color='green'>"
	strDisplay = strDisplay & intSuccessfulPingCount
	strDisplay = strDisplay & "</font></td>"
	strDisplay = strDisplay & "</tr>"
	strDisplay = strDisplay & "<tr>"
	strDisplay = strDisplay & "<td><font color='red'>Unsuccessful pings</font></td>"
	strDisplay = strDisplay & "<td><font color='red'>"
	strDisplay = strDisplay & intUnsuccessfulPingCount
	strDisplay = strDisplay & "</font></td>"
	strDisplay = strDisplay & "</tr>"
	strDisplay = strDisplay & "</table>"
	strDisplay = strDisplay & "</p>"

	strDisplay = strDisplay & "<hr>"

	strDisplay = strDisplay & "<p>"
	strDisplay = strDisplay & "Auto Close Enabled: "
	strDisplay = strDisplay & AUTO_CLOSE
	strDisplay = strDisplay & "</p>"

	strDisplay = strDisplay & "<hr>"

	strDisplay = strDisplay & p_strSuffix

	objExplorer.Document.Body.InnerHTML = strDisplay
End Sub


'This function pings the specified host
Function Ping(p_strHost, p_boolDisplay)
	Dim objPing, objStatus

	Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery ("select * from Win32_PingStatus where address = '" & p_strHost & "'")

	For Each objStatus in objPing
		If IsNull(objStatus.StatusCode) or objStatus.StatusCode0 then
			Ping = False
			If p_boolDisplay Then
				WScript.Echo "Status code is " & objStatus.StatusCode
			End If
		Else
			Ping = True
			If p_boolDisplay Then
				Wscript.Echo "Bytes = " & vbTab & objStatus.BufferSize
				Wscript.Echo "Time (ms) = " & vbTab & objStatus.ResponseTime
				Wscript.Echo "TTL (s) = " & vbTab & objStatus.ResponseTimeToLive
			End If
		End if
	Next
End Function 


'Beep the PC speaker a number of times equal to the p_intBeeps parameter
Function Beep(p_intBeeps)

	Dim objShell, intCount, strCommand

	'Check we have a valid number of beeps not fool proof but it will do for now
	Beep = False
	If IsNumeric(p_intBeeps) Then
		If p_intBeeps > 0 Then
			Beep = True
		End If
	End If

	If Beep Then
		'Build the command string to run
		strCommand = "cmd /c echo"
		For intCount = 1 to p_intBeeps
			strCommand = strCommand & " " & chr(007)
		Next

		'Run the command in the background
		Set objShell = Wscript.CreateObject("wscript.Shell")
		objShell.Run strCommand, 0

		Beep = True
	End If
End Function

There are also a few options in the script to specify numbers of beeps for successful and unsuccessful pings as well as auto closing of the Internet Explorer window and lengths of pauses between pings and before auto closing the window.

Advertisements
h1

Google May Harm Your Computer

31/01/2009

Like almost everyone else with an Internet connection on the planet i use Google a lot.  Today though they seem to be having problems.  Everything I’m searching for seems to have an associated warning – this site may harm your computer.

I signed out of iGoogle, tried google.co.uk and google.com.  All were affected and notably Google itself seems to be unsafe…

Is Google self harming?

Is Google self harming?

Following the link give some additional details of what this may mean, but the diagnostic page is perhaps under a bit of stress at the moment.

Global Warning

Global Warning

Better luck next time

Better luck next time

I think Google may be a bit poorly today.  Hopefully it’ll be back to normal soon….  I’m not sure what a world on the Internet without google to guide the way would be like.  I don’t like the sound of that just now.

h1

NoteTab Clip – Use Empty File

29/01/2009

A little clip I like to use in NoteTab is one for ensuring that I have an empty file.  I usually call it using the ^!FarClip command from a standard library before I dump out the results of something where I always want it to be separate.  It’s a very short and sweet little clip – just paste it into your favourite little clip library.

H="_Use Empty File"
;If the current document isn't blank then
;open a new blank document
!If ^$GetTextSize$ = 0 Skip
^!TOOLBAR New Document

Also note that the underscore on the header. This ensures that the clip can’t be run separately but only from another clip. You can remove this if you like, but if you want to run it separately I’d suggest a quick glance and pressing the new document button or pressing CTRL+N might be faster.

h1

NoteTab Clipping – Detect Parameter Passing

27/01/2009

When working with NoteTab clips I like to be efficient and reuse clips just like programmers do with functions, subroutines, code libraries, etc. So one little thing I like to use when dealing with some clips is a conditional statement that allows the clip to work out if it was called from another clip with a parameter.

To accomplish this we’re actually going to use something that the NoteTab Clip help file recommends against – converting 4 (decimal) to a character using the ^$DecToChar()$ function. ASCII(004) is an end of transmission character, but it turns our that we can test against this on the parameter place holder. Just trying to measure the size as zero when a parameter is passed for example curiously gives a length of two characters.

^!If ^& > ^$DecToChar(4)$^$DecToChar(4)$ PARAM_PASSED Else NO_PARAM

The two go to labels used here show the logic. PARAM_PASSED is where a parameter has been passed and NO_PARAM is where no parameter was passed.

This snippet of code is useful because it can be used for example at the start of a clip that could be run manually by a user taking in a parameter through an input box. It can also be used at the end in determining how to deal with a result – display it, insert it, pass it back in the %RESULT% variable, etc.

Please note that the code does not distinguish between a clip called with no parameters from another clip and a clip run manually. Of course if the clip is called from another clip using a dummy parameter it could be used as a crude way of doing this.

h1

Sticky Note Sorting

20/01/2009

Ever sorted sticky notes (affinity diagramming) on a wall and then had to copy it all down?  Well perhaps StickySorter from Microsoft Offics Labs might be just the thing you need.  Combine it with an electronic whiteboard like MIMIO or a projector and a gyroscopic/wireless keyboard & mouse and you can really get to work.  With Microsoft Surface on the horizon it could be even more natural and just ever so slightly Minority Report … but not everything’s perfect.

h1

Screen Capture

12/01/2009

For a simple screen shot taking tool, Lightscreen is a free piece of software that sits in the system tray and can assign hot keys to capturing screen areas as well as the usual desktop and active window.  It can also be set to dump out direct to file.

There’s also a much more powerful tool called Screenshot Captor that not only takes screen shots, but can also add additional graphics to them.  It can also help in presentations by highlighting/dimming screen areas.  Again it’s free but you can also donate to the author if you like it.

h1

PowerPoint – Mastering the canvas

12/01/2009

Every presentation these days involves Microsoft PowerPoint.  After a while no matter how much multimedia you add to it, your presentation can still look a bit dull and boring.  In order to make your next presentation a bit different why not try pptPlex – a PowerPoint plugin that rebuilds a set of slides into a single ‘zoomable canvas’.

I saw this used by James Senior of Microsoft at the Misco Expo in October 2008 on a presentation about SBS, EBS and MS Server 2008.  It worked really well and added a new dimension to the way in which the presentation was delivered.  It also allowed him to skip around and to show areas that were collections of slide that fit together like a jigsaw but could then be zoomed in.