This little script helps to locate a (cisco) switch which has multiple connections on one port.
The result is a txtfile with the name, ip and port of the switch.

Software used:

  1. cut.exe
  2. sort.exe
  3. uniqe.exe
  4. tst10.exe aka Telnet Scripting Tool

The first 3 files can found in the CoreUtils archive.

The Telnet Scripting Tool can be found on Jerry Mannel’s blog

Preparations:

  1. Create a folder and place the files
  2. Create a file, eg switches.txt
  3. Save the source code, which can be found at the bottom of this article, as something.vbs

- Switches.txt should be in the following format:

ip-address;serietype;fullname (in most cases serietype=2950)

10.10.10.1;2950;switch-01
10.10.10.2;2950;switch-02

To run: open a commandprompt and type “wscript something.vbs”

The Code:

We begin by setting up our environment.

set wshshell = createobject("wscript.shell")
set fso= createobject("scripting.filesystemobject")
set switchlist = fso.opentextfile("switches.txt")
 
if fso.fileExists("result.txt") then
	fso.deleteFile "result.txt", true
end if
 
set result = fso.openTextFile("result.txt",8,true)

We loop switches.txt until all items are processed and make sure that previous created files are removed.

do until switchlist.atendofstream
 
	'--- Remove all previous files ---
 
	if fso.fileExists("output.txt") then
		fso.deleteFile "output.txt", true
	end if
	if fso.fileExists("temp.txt") then
		fso.deleteFile "temp.txt", true
	end if
	if fso.fileExists("double.txt") then
		fso.deleteFile "double.txt", true
	end if
 
	switch = switchList.readLine
	matrix = split(switch, ";")
	ip = matrix(0)
	typeswitch = matrix(1)
	switchname = matrix(2)
 
	if fso.filEexists("script.txt") then
		fso.deleteFile "script.txt", true
	end if

Since not every IOS uses the same commands, we split our code up.

if typeswitch = "2950" then
 
	set script = fso.openTextFile("script.txt",8,true)
		script.writeline ip & " 23"
		script.writeline "send " & """<passwd>\m"""
		script.writeline "wait " & """>"""
		script.writeline "send " & """term len 0\m"""
		script.writeline "wait " & """>"""
		script.writeline "send " & """show mac-address-table | include Fa0/\m"""
		script.writeline "wait " & """>"""
		script.writeline "send " & """quit\m"""
	script.close
 
	else 'type=2948
 
	set script = fso.openTextFile("script.txt",8,true)
		script.writeline ip & " 23"
		script.writeline "send " & """<passwd>\m"""
		script.writeline "wait " & """>"""
		script.writeline "send " & """set len 0\m"""
		script.writeline "wait " & """>"""
		script.writeline "send " & """show cam dyn | exclude 2/49\m"""
		script.writeline "wait " & """>"""
		script.writeline "send " & """quit\m"""
	script.close
 
	end if

The code above is necessary for using the Telnet Scripting Tool. More information about its use can be found on this blog.

commandoTelnet = "TST10 /r:script.txt /o:output.txt"
	wshshell.run commandoTelnet, ,True	
 
	wscript.sleep 3000
 
	if typeswitch = "2950" then
 
	commandoGrep = "cmd /c " & """grep -e " & """DYNAMIC""" & " -e " & """STATIC""" & " output.txt > temp.txt"""
	wshshell.run commandoGrep, , True
 
	commandoCut = "cmd /c " & """cut -c 39- temp.txt > test.txt"""
	wshshell.run commandoCut, , True
 
	else '=2948
 
	commandoGrep = "cmd /c " & """grep -e " & """[ALL]""" & " output.txt > temp.txt"""
	wshshell.run commandoGrep, , True
 
	commandoCut = "cmd /c " & """cut -c 39- temp.txt > test.txt"""
	wshshell.run commandoCut, , True
 
	end if
 
	commandoFindDuplicates = "cmd /c" & """sort test.txt |uniq -d > double.txt"""
	doubles = wshshell.run(commandoFindDuplicates, ,True)
 
	if fso.fileExists("double.txt") then
		set readDoubleTxt = fso.openTextFile("double.txt")
		do until readDoubleTxt.atendofstream
			routerOpPort = readDoubleTxt.readline
			result.writeline switchname & "(" & ip & ")" & "->" & routerOpPort
		loop
	readDoubleTxt.close
	end if
 
loop
result.close
Wscript.Echo "Script finished !"

The resulting output is:

switch-02(10.10.10.1)->Fa0/45
switch-02(10.10.10.2)->Fa0/46
switch-03(10.10.10.3)->Fa0/2
switch-06(10.10.10.4)->Fa0/33
switch-07(10.10.10.5)->Fa0/41
switch-08(10.10.10.6)->Fa0/24

Although this script can be further optimized, it does the job for me :)

The fullcode :


 

Recently I bought myself an iPod Touch 8Gb and off course a couple of (usefull) applications/games.

Wifitrak (0,79 euro)

WifiTrak helps you find FREE and open WiFi hotspots and public access points quickly and easily.

WifiTrak scans for all available WiFi devices and networks in the area and tests each network it finds for usability. It shows a list of the networks sorted from most useable (open, not redirected, strongest signal) to least useable (secured or hidden, weak signal). It can automatically notify and launch mail or a browser when it finds a suitable network 

Notemaster Lite (Free)

Notemaster (Lite) let you easily create  notes containing text, images, and headers.  These notes can be organized with categories and be password-protected for privacy.

Facebook (Free)

Not much introduction needed :-) - Facebook for iPhone makes it easy to stay connected and share information with friends. Use your iPhone to start a conversation with Facebook Chat, check your friends’ latest photos and status updates, look up a phone number, or upload your own mobile photos to Facebook while on the go.

iDroid Mini (Free)

iDroid Mini Browser is an innovative browser designed specifically for the iPhone/iPod. Inspired by iPhone’s Safari,Android browser and Opera mini including full screen, tabs, smart url, etc.

For me a nice replacement until Opera comes out with their version for the ipod ;)

FileApp (Free)

FileApp browser displays files by folders, alphabetically, by date of copy or by file type.
You can view almost every file with the build-in viewer; such as:

PDF Viewer, Microsoft Office (Word, Excel and PowerPoint), Images (JPG, PNG, GIF, TIFF and others), iWork (Pages, Numbers and Keynotes), Open Office (OpenDocument) (Text, Spreadsheet, Presentation), Plain Text and RTF (Rich Text Format),  Audio (MP3 VBR, AAC, Audible, Apple Lossless, AIFF, WAV, CAF), Video (standard iPhone formats : H.264, MPEG-4), Web Archives,  HTML files, ZIP Archives, Comic Books, etc… 

iDownload (1,59 euro)

iDownload allows you to download files directly to your iPhone or iPod touch and share them to any browser enabled device (pc, mac, linux, iphone, ipod touch, mobile devices, etc). You can use iDownload like a normal browser and when u click a download link i should pop up an alert asking u if u want to download or save the link.

After downloading you can share your files to any computer or mobile device as long as it is connected to same wifi network.

Part 2 will follow soon.

© 2012 Ceekes boarderline Suffusion theme by Sayontan Sinha