Hi,
I like to present to you my new script that allow to start a external telnet program wait until gets open and then change its window title, resize it to the specified needs from CLI args and after all send a ENTER key into the console to show the device prompt.
Back in the days I've try to use "
expect", "
cmdow" to rename/press that enter to the device, but there is a new option "
AutoHotKey" scripting ;))
I'm not so good at selling something and I'll let you decide if can be a option or not :))
Quote:
Download: [
console_wrapper_v0.2.zip]
Script used to open a telnet program to a GNS3 device Console/AUX
1) It will change the Window Title according to the device hostname.
2) Also will resize that window as specified in <X_WinSize> <Y_WinSize>
Those values are in pixels, recommended 920 420.
3) After the telnet connectivity is done, it will push some "Enter" keys
until the device console from Routers (Dynamips) will show the prompt.
This is useful for me because otherwise that router eats one CPU core.
Works great with Telnet, PuTTY, TeraTerm 3.1.3 and SecureCRT 6.7.5
other CLI/GUI terminals might work as well, but only those I've tested.Usage:
console_wrapper.exe "PATH\program.exe" %h %p %d <X_WinSize> <Y_WinSize>
GNS3 Ex:
console_wrapper.exe telnet.exe %h %p %d 920 420
console_wrapper.exe putty.exe %h %p %d 920 420
console_wrapper.exe "X:\..\ttermpro.exe" %h %p %d 920 420
console_wrapper.exe "X:\..\SecureCRT.exe" %h %p %d 920 420
CLI Ex:
console_wrapper.exe putty.exe 127.0.0.1 2002 R1 920 420
Attachment:
Example.jpg [ 43.73 KiB | Viewed 14646 times ]
And I still have some other stuff to show (all that is already included in this script)...
For conservators SecureCRT users wrote:
Code:
'New script that "press" a enter into the device console to show the prompt
'SecureCRT.exe /NOMENU /NOTOOLBAR /SCRIPT "<PATH>\Script.vbs" /ARG "%d" /TITLEBAR "GNS3 Terminal Manager - SecureCRT" /T /N "%d" /TELNET %h %p
#$Language = "VBScript"
#$Interface = "1.0"
crt.Screen.Synchronous = True
Sub main
'crt.window.caption = crt.arguments(0) 'This can be done also by CLI argument "/N %d"
crt.Sleep 1000
crt.Screen.Send chr(13)
End Sub
For conservators TeraTerm users wrote:
Command line that enable using a custom window title (Dynamips is changing it remotely, but is good for Qemu/Pemu)
ttermpro.exe /T /W="%d" %h:%p
This is version 2 of CMD script for telnet wrote:
Code:
@ECHO OFF
:: X:\Tools\telnet-console.bat %h %p %d v1
:: Please adjust the time between opening consoles to all devices to 0,5 or 1 seconds
IF "%~4"=="" (GOTO v1) ELSE (GOTO %~4)
:v1
START /B CMD /C "TELNET %1 %2&ECHO.&ECHO Telnet connection to '%3' console port is lost!&ECHO Press any key to exit...&PAUSE >NUL"
CMDOW " %1" /SIZ 905 400 /REN "%3 - Console port - [%1:%2]" 2>NUL || CMDOW "%1" /SIZ 905 400 /REN "%3 - Console port - [%1:%2]" 2>NUL
GOTO :EOF
:v2
CMDOW @ /MIN
START CMD /C "TELNET %1 %2&ECHO.&ECHO Telnet connection to '%3' console port is lost!&ECHO Press any key to exit...&PAUSE >NUL"
SLEEP 1s
FOR /F "usebackq tokens=1" %%G IN (`WMIC PROCESS get ProcessId^,Commandline^| GAWK "/CMD.*%1 %2/{print $(NF-1);exit}"`) DO (
FOR /F "tokens=1" %%L IN ('CMDOW ^| GAWK "/%%G.*cmd/{print $1;exit}"') DO (
CMDOW %%L /SIZ 905 400 /REN "%3 - Console port - [%1:%2]"
))
GOTO :EOF
Here I propose a new version of the default baseconfig.txt from GNS3 directory wrote:
Code:
!This configure as well the aux line for all devices and puts privilege 15 on console so you don't need to say enable all the time ;)
!
hostname %h
!
no ip domain lookup
ip domain-name lab.local
!
line con 0
exec-timeout 0 0
logging synchronous
privilege level 15
no login
line aux 0
exec-timeout 0 0
logging synchronous
privilege level 15
no login
!
And I also want to ask Jeremy to add a new "Toolbar" in GNS3 in which users can add shortcuts to custom scripts ;))Script used to close putty windows for GNS3 wrote:
Code:
@ECHO OFF & SETLOCAL
::Script used to close putty windows for GNS3
::I can use TASKKILL to force kill putty, but it will not send the FIN packet to close the TCP connection to
::Dynamips and Qemu, and Qemu will not allow to open a new connection after that, and will simply close any new connection
::Putty has to be configured for "Default Setings" (in Window->Behaviour->Warn before closing window) to not ask for confirmation when the window is closed!
FOR %%G IN (Dynamips 127.0.0.1 localhost "PuTTY (inactive)") DO (
TASKKILL /IM "putty.exe" /FI "WINDOWTITLE eq %%~G*" >NUL 2>&1
)
ENDLOCAL
Send a write memory to all routers - Dynamips only wrote:
Code:
@ECHO OFF & SETLOCAL
::IP Address for telnet connection
SET IP=127.0.0.1
::Timeout to wait until close the conection to the console ports (KILL NC.exe)
SET WAIT=5s
::Pattern from TCP port on which Dynamips Console/AUX is listening (REGEX)
SET PORT=20
IF NOT "%~1"=="" GOTO TELNET
ECHO *******[ GNS3/Dynamips Router Config Save ]*********&ECHO.
FOR /F "" %%G IN ('NETSTAT -nabp TCP 2^>NUL ^| GAWK "{if($0~/:%PORT%.*LISTENING/){split($2,a,\":\"); x=a[2]}else if(x && $0~/dynamips.exe/){print x; x=0}}"') DO (
SET FOUND=1
ECHO Telnet to "%IP%:%1" ...
REM START "" "%~0" %%G & REM For DEBUG
START "" CMD /C ""%~0" %%G"
)
IF NOT DEFINED FOUND GOTO Final
ECHO.&ECHO Wait %WAIT% before killing telnet conections ...
SLEEP %WAIT%
TASKKILL /F /IM "NC.exe" >NUL 2>NUL
GOTO Final
:TELNET
ECHO.&ECHO ***** Telnet to "%IP%:%1" *****
(
:: Here you can type what command should be send to the Router/ASA
GAWK "BEGIN{ print \"\r\n\" }"
ECHO end
ECHO write memory
GAWK "BEGIN{ print \"\r\n\" }"
) | NC -n %IP% %1 | GAWK "{if($0~/Dynamips/) $0=substr($0,13); print $0}"
GOTO :EOF
:Final
ECHO Final!
SLEEP 1s
ENDLOCAL
Loopback NICs manager for Windows - v0.2.1 wrote:
Code:
::v0.2.1, 01.may.2012, N!NiX and Jeremy Grossmann
@ECHO OFF&SETLOCAL
TITLE Loopback NICs manager for Windows - v0.2.1
SET PASS=0&SET N=0&SET CLI=
ECHO 1^) Checking Windows version... & REM http://en.wikipedia.org/wiki/Ver_(command)
FOR /F "usebackq tokens=2,3 delims=. " %%G IN (`@FOR /F "tokens=2 delims=[]" %%L IN ^('@VER'^) DO @ECHO %%L`) DO (
IF %%G LSS 5 GOTO ERROR_OLD_OS
IF %%G EQU 5 IF %%H LSS 1 GOTO ERROR_OLD_OS
SET PASS=1
)
IF "%PASS%" == "0" (GOTO ERROR_OLD_OS) ELSE (SETLOCAL ENABLEEXTENSIONS)
:: Try to do something that is off limits if not elevated privilege
ECHO.&ECHO 2^) Checking script privileges...
REG QUERY "HKU\S-1-5-19" >NUL 2>&1 || GOTO ERROR_NOT_ADMIN
CLS
CD /D "%~dp0"
::Detecting system CPU architecture x86/x64
SET | FIND "PROCESSOR_ARCHITECTURE=x86" >NUL && (SET DEVCON=devcon_x86.exe) || (SET DEVCON=devcon_x64.exe)
:CHOOSE
SET Q=&SET /A N+=1
IF NOT "%~1"=="" (
SET Q=%~1
SET CLI=1
SHIFT
) ELSE (
IF %N%==1 (
CALL :MENU
ECHO.&SET /P Q="Choose a option: "
) ELSE (
ECHO.&SET /P Q="Choose a option: "
)
)
IF "%Q%"=="1" (CALL :LIST & IF NOT DEFINED CLI (GOTO CHOOSE) ELSE (GOTO :EOF))
IF "%Q%"=="2" (CALL :INSTALL & IF NOT DEFINED CLI (GOTO CHOOSE) ELSE (GOTO :EOF))
IF "%Q%"=="3" (CALL :REMOVE_MENU & IF NOT DEFINED CLI (GOTO CHOOSE) ELSE (GOTO :EOF))
IF "%Q%"=="4" (CALL :REMOVE_ALL & IF NOT DEFINED CLI (GOTO CHOOSE) ELSE (GOTO :EOF))
IF "%Q%"=="5" GOTO REBOOT
IF "%Q%"=="6" GOTO :EOF
IF "%Q%"=="?" (CALL :MENU & IF NOT DEFINED CLI (GOTO CHOOSE) ELSE (GOTO :EOF))
IF "%Q%"=="/?" (CALL :MENU & IF NOT DEFINED CLI (GOTO CHOOSE) ELSE (GOTO :EOF))
IF "%Q%"=="-h" (CALL :MENU & IF NOT DEFINED CLI (GOTO CHOOSE) ELSE (GOTO :EOF))
ECHO Incorect option! & IF NOT DEFINED CLI (GOTO CHOOSE) ELSE (ECHO.&ECHO ^[Available options^]&GOTO MENU)
:LIST
ECHO.&ECHO Installed Loopback interfaces:
%DEVCON% find *MSLOOP
GOTO :EOF
:INSTALL
ECHO.&ECHO Installing a new Loopback interface (Takes about 30s)...
%DEVCON% install %WINDIR%\inf\netloop.inf *MSLOOP
ECHO.&ECHO Warning: To make this interface available&ECHO you have to reboot your computer!
GOTO :EOF
:REMOVE_MENU
SET LNR=0
ECHO.&ECHO Installed Loopback interfaces:
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "tokens=1 delims= " %%G IN ('%DEVCON% find *MSLOOP ^| FIND "ROOT"') DO (
SET /A LNR+=1
ECHO !LNR!^) - '%%G'
)
ECHO.&SET QNR=&SET /P QNR="Please select the interface number: "
SET LNR=0
FOR /F "tokens=1 delims= " %%G IN ('%DEVCON% find *MSLOOP ^| FIND "ROOT"') DO (
SET /A LNR+=1
IF !LNR!.==%QNR%. (
ECHO Removing interface '%%G'...
%DEVCON% remove @%%G
SETLOCAL DISABLEDELAYEDEXPANSION
GOTO :EOF
)
)
SETLOCAL DISABLEDELAYEDEXPANSION
ECHO Incorrect interface number!
GOTO :EOF
:REMOVE_ALL
ECHO.&ECHO Remove all Loopback interfaces from this system...
%DEVCON% remove *MSLOOP
GOTO :EOF
:MENU
ECHO.
ECHO 1^) List all installed Loopback interfaces
ECHO 2^) Install a new Loopback interface (reboot required)
ECHO 3^) Remove a Loopback interface
ECHO 4^) Remove all Loopback interfaces
ECHO 5^) Reboot PC
ECHO 6^) Quit
ECHO ?^) This Menu
GOTO :EOF
:ERROR_OLD_OS
ECHO.
ECHO This script is not for Windows 95, 98 or ME.
ECHO.
PAUSE >NUL
GOTO :EOF
:ERROR_NOT_ADMIN
ECHO.
ECHO This script is not running with sufficient privileges.
ECHO.
ECHO Under Windows Vista and later Windows versions, you should launch this
ECHO script by right-clicking and choosing Run As Administrator.
ECHO.
PAUSE >NUL
GOTO :EOF
:REBOOT
ECHO.&ECHO This computer is restarting now! &MSG "%USERNAME%" "This computer is restarting now!"
SHUTDOWN -r -t 0
PAUSE >NUL
GOTO :EOF