Remembering Network Devices

Remembering Network Devices

A few years back when starting a new role providing 3rd Level support for an international network with over one hundred devices in my remit, it became apparent very quickly I was going to struggle to remember all the IP addresses in a few days or even the host names for that matter. There was no standard tools being use to connect all the devices, Windows XP telnet seem to be the tool of choice.

Most of the devices had some standards naming conventions. Like site code and type of device. So Lon_SW1 would be switch 1 in London. I decided to dust of my scripting skills and make life easier for myself.

The Script

Once you† run the script you get prompted for some characters that make up the device name. So if i type “lon” not case-sensitive and hit enter then all the London devices are displayed, then chose the device from the numbered list and it will startup the putty session.

There are 3 bits of code to make this work

  • DevAccess.cmd ñ this is the Windows CMD file to call the VBscript
  • DevAccess0.1.vbs ñ this the main code
  • Devlist.txt ñ list of devices, make sure you do not create any duplicates as it will not work,

Put them in a directory on your Windows PC and create a shortcut to DevAccess.cmd. You will need to download kitty.exe (http://www.9bis.net/kitty/) and put it in the same directory.

Update:

I had previously used putty at work without port number and used command line “putty -protocol ipaddress”, however when I wrote this post I needed to use “ipaddress:port number” †to access my lab console and changed my command line to “putty protocol://ipaddress:port” †which is ok for telnet; quite rightly Ben Johnson pointed out that putty does not support ssh using this command line format so I have†updated the code to use kitty.exe instead, which seems to work fine.

Here is a quick demo

ConnecttoDeviceDemo

DevAccess.cmd


REM **** Runs Scipt to Search and Connect to Devices
REM **** This works of the devlist.txt located on
REM **** c:program filesdevaccess
REM **** also have Putty.exe in the same directory as the script
ì%SYSTEMROOT%SYSTEM32CSCRIPT.EXEî //nologo ì%~dp0DevAccess0.1.vbsî

DevAccess0.1.vbs


inifile="devlist.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim oMyDevs
set oMyDevs = CreateObject("Scripting.Dictionary")
Const ForReading = 1
Dim aDeviceInfo
if objFSO.FileExists(inifile) then
Set objFile = objFSO.OpenTextFile(inifile, ForReading)
Do Until objFile.AtEndOfStream
strdev = objFile.ReadLine
aDeviceInfo = Split(strdev, ",", -1, 1)
oMyDevs.Add aDeviceInfo(0),"kitty " & aDeviceInfo(2) & "://" & aDeviceInfo(1) & " -title " & aDeviceInfo(0)
wscript.echo aDeviceInfo(0),"kitty " & aDeviceInfo(2) & "://" & aDeviceInfo(1) & " -title " & aDeviceInfo(0)
loop
objFile.Close
else
MsgBox inifile & " is missing, copy it from MyNMS",0,"Missing Device Master List"
wscript.quit(0)
End If
set oShell=CreateObject("Wscript.Shell")
MyDevices = oMyDevs.Keys
do while 1
strInputChoice=""
redim startkitty(1)
devicematch = InputBox("Enter device characters","Search for Device (enter x to quit)",,,0)
if ucase(devicematch)="X" then
wscript.quit(0)
end if
index=0
Wscript.Echo "======== Device List ============================================"
For Each strDevice in MyDevices
if instr(1 ,ucase(strDevice),ucase(devicematch),1) then
index=index+1
Wscript.Echo index & " ) " & strDevice & " " & oMyDevs.Item(strDevice)
strInputChoice=strInputChoice & index & " ) " & strDevice &vbCR &vbLF
redim preserve startkitty(index)
startkitty(index)= oMyDevs.Item(strDevice)
end if
Next
Wscript.Echo "================================================================="
if index >1 then
opendevice=0
opendevice=InputBox(strInputChoice,"OpenDevice",,,0)
if ucase(opendevice)="X" then
wscript.quit(0)
end if
if isnumeric(opendevice) then
if int(opendevice) > 0 and int(opendevice) <=index then
wscript.echo "Starting SSH sessions to " & startkitty(opendevice)
oShell.Run(startkitty(opendevice))
end if
end if
elseif index=1 then
wscript.echo "Starting SSH sessions to " & startkitty(1)
oShell.Run(startkitty(1))
else
wscript.echo "No Devices Found containing " & devicematch
end if
Loop

Devlist.txt


Belkin,192.168.1.31:23,telnet
Rack01R1,192.168.1.31:4001,telnet
Rack01R2,192.168.1.31:4002,telnet
Rack01R3,192.168.1.31:4003,telnet
Rack01R4,192.168.1.31:4004,telnet
Rack01R5,192.168.1.31:4005,telnet
Rack01R6,192.168.1.31:4006,telnet
Rack01R7,192.168.1.31:4007,telnet
Rack01R8,192.168.1.31:4008,telnet
Rack01R9,192.168.1.31:4009,telnet
Rack01R10,192.168.1.31:4010,telnet
Rack01R11,192.168.1.31:4011,telnet
Rack01R12,192.168.1.31:4012,telnet
PowerBar,192.168.1.31:4016,telnet

Summary

A quick method of navigating you way around devices, and if you change the telnet to ssh that should work too; the list above is just my LAB access at home, I do not want to be publishing customer site information.

Comments

  1. Last time I checked, as I have a few times, your out-of-the-box PuTTY doesn’t support an SSH URL formatted thusly: ssh://x.x.x.x. It does support telnet://x.x.x.x though, obviously. After a bit of faffing around with various different workarounds for this issue I ended up finding a version of PuTTY that someone had kindly recompiled to support this URL scheme. There are different versions available out there, but this is the one that I found worked for me:

    http://schipka.com/archives/34

    Hope you find it useful.

    T: @silverbenz

  2. I updated the code at 17:45 GMT on 20/12 as I noticed an issue with missing “loop” statement when trying to import into my work environment. All should be good now.
    Regards
    John

  3. I believe a small change in DevAccess.cmd will make it more universal:
    “%SYSTEMROOT%SYSTEM32CSCRIPT.EXE” //nologo “%~dp0DevAccess0.1.vbs”