Author Topic: [Tutorial] SHH or Telnet to a device  (Read 26234 times)

0 Members and 1 Guest are viewing this topic.

incubii

  • Newbie
  • *
  • Posts: 3
[Tutorial] SHH or Telnet to a device
« on: April 23, 2008, 09:02:56 PM »
Hi guys i thought i would contribute something to you all. I will show you how i setup my Visio 2003 shapes to allow me to SSH or Telnet to device they represent.

Step 1
Open up the shape sheet and add two custom properties.
  • Prop.IPAddress
  • Prop.ConnectionType


Step 2
Edit Prop.ConnectionType to be Type 4 with a format of "ssh;telnet". This will allow you to set in the custom properties window what connection type to use.


Step 3
Add a new action and for the action add
Code: [Select]
=CALLTHIS("ThisDocument.manageDevice",,Prop.IPAddress,Prop.ConnectionType)
And for the menu put "Manage Device"


Step 4
Open up the VBA editor for your document and paste the following code in

Code: [Select]
Sub manageDevice(shpObj As Visio.Shape, strHost As String, strType As String)
    Dim strCommand, TaskID, strPuttyLocation, Msg, Style, Title, Help, Ctxt, Response, MyString
    strPuttyLocation = "C:\Program Files\PuTTY\putty.exe"
    strCommand = strPuttyLocation + " -" + strType + " " + strHost
   
       
    Msg = "Use " + strType + " to connect to the device on " + strHost + "?"     ' Define message.
    Style = vbYesNo + vbInformation + vbDefaultButton2    ' Define buttons.
    Title = "Are you sure you want to connect?"    ' Define title.
    Response = MsgBox(Msg, Style, Title)
    If Response = vbYes Then    ' User chose Yes.
        TaskID = Shell(strCommand, vbNormalFocus)
    Else    ' User chose No.
       ' Perform some action.
    End If
End Sub

What this does is take the IPAddress and ConnectionType you supplied and execute Putty with those passed to it. It has a message box to ask you if you would like to use connection type to ipaddress. Just to be sure.

Make sure you set the strPuttyLocation variable in the Subroutine to where your putty is located.

Thats it! I know its not very portable due to relying on where putty is but this works great for me at work as putty is on a shared drive that everyone can see.

Forgot to say that you can now right-click on the shape and a new menu option "Manage Device" will be there. Click on this and it will either telnet or ssh to the IPAddress you set.
« Last Edit: April 23, 2008, 09:04:28 PM by incubii »

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: [Tutorial] SHH or Telnet to a device
« Reply #1 on: April 25, 2008, 11:26:53 AM »
I personally use the secureCRT product for SSH. I think ‘putty’ may be a free implementation. I also use the shell command for calling the terminal services client (MSTSC) so that you can log onto servers/work stations

‘ where the visCell is pointed at the appropriate custom property
‘ note that I put the path into the command string for the executable
 strCommand = "c:\windows\system32\mstsc.exe /v:"  & visCell.ResultStr("") & " /console"

There are a couple of exposures in using a shell to call routines. The one I run into most is the x32 vs. x64 binary one on systems. The problem is that when the system is x64 and you are allowing x32 applications, there have to be both versions of the application for the shell to work. This hits on things like the telnet command which MS only puts out as a x32 bit version (i.e. call it via a shell on a x64 bit machine and it will fail). A work around in this case was to copy the x32 dll to the x64 directory, or the brute force approach to use the SSH product as the default telnet client.


d33d3345

  • Newbie
  • *
  • Posts: 6
Re: [Tutorial] SHH or Telnet to a device
« Reply #2 on: February 21, 2012, 06:47:59 PM »
All good and works, but I need to connect to a given port for an device.

How would I connect telnet (putty) on a different port, say 2001

I will be designing many network diagrams and wish to have lots of network equiptment that I can telnet to on the same IP address but with different ports

R1 192.168.80.129:2001
R2 192.168.80.129:2002

etc etc

Help!

Many thnaks John

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: [Tutorial] SHH or Telnet to a device
« Reply #3 on: February 21, 2012, 07:25:50 PM »
one of us is very confused, AFAIK
a.) IP does not allow duplicate addresses in a network. Device addresses have to be unique (although NAT can play games with that when mapping wan to lan).
b.) The port address of an application (although modifiable in some cases) is under the direct control of the application after you get to the correct device. You don't select devices based on ports, you select (basically a queue id) an application on a specific device.
c.) Whether a specific port can be used is up to the application. So you might want to investigate that first.
al
ps you might check out some of Comer's books on tcp/ip

d33d3345

  • Newbie
  • *
  • Posts: 6
Re: [Tutorial] SHH or Telnet to a device
« Reply #4 on: February 21, 2012, 07:54:05 PM »
Thanks for your quick reply,

Im using a local network lab simulator, wich allows me to build Cisco networking labs for testing.  It has up to 30 devices which run in a VM and allows me to connect to each device via my locally assigned IP address range;

192.168.80.129

Each device has a different port assigned;

R1 192.168.80.128:2001
R2 192.168.80.128:2002
etc
etc

I can get putty to open based on the tutorial, but it then closes a few seconds later, I beleive as it does not have the correct port for the device.

Any ideas of how this can be achaived?

Regards,
John

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: [Tutorial] SHH or Telnet to a device
« Reply #5 on: February 21, 2012, 11:18:09 PM »
I'd suggest that before you attempt to make the drawing work, you test it with a legitimate session. That way you're not wasting your time when the problem isn't in visio. The other issue is since you're working in a cisco lab environment you have to worry about what ports are open in the firewalls since you're not working with 'well know ports'.
al

d33d3345

  • Newbie
  • *
  • Posts: 6
Re: [Tutorial] SHH or Telnet to a device
« Reply #6 on: February 22, 2012, 08:36:00 AM »
Yes, it works fine locally without issues.

All I need now is how to enable the putty session to a specific port.

Any ideas  how to port map putty through the visio code?

192.168.80.128:2001
192.168.80.128:2002

etc etc...

Any help much appreciated :)



d33d3345

  • Newbie
  • *
  • Posts: 6
Re: [Tutorial] SHH or Telnet to a device
« Reply #7 on: February 22, 2012, 09:43:00 AM »
Putty supports command line variables, but i have tried in VB Editor.  I'm not sure how to add.

There is a couple of ways to apply the syntax for putty.  How do you write this into VB editor??? my VB code is below the putty command line variables.

Putty command line variables; -P: specify a port number

The -P option is used to specify the port number to connect to. If you have a Telnet server running on port 9696 of a machine instead of port 23, for example:

putty -telnet -P 9696 host.name
plink -telnet -P 9696 host.name
(Note that this option is more useful in Plink than in PuTTY, because in PuTTY you can write putty -telnet host.name 9696 in any case.)

This option is equivalent to the port number control in the Session panel of the PuTTY configuration box (see section 4.1.1). http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter4.html#config-command

Here is my VB code;

Sub manageDevice(shpObj As Visio.Shape, strHost As String, strType As String)
    Dim strCommand, TaskID, strPuttyLocation, Msg, Style, Title, Help, Ctxt, Response, MyString
    strPuttyLocation = "C:\Program Files\PuTTY\putty.exe"
    strCommand = strPuttyLocation + " -" + strType + " " + strHost
   
       
    Msg = "Use " + strType + " to connect to the device on " + strHost + "?"     ' Define message.
    Style = vbYesNo + vbInformation + vbDefaultButton2    ' Define buttons.
    Title = "Are you sure you want to connect?"    ' Define title.
    Response = MsgBox(Msg, Style, Title)
    If Response = vbYes Then    ' User chose Yes.
        TaskID = Shell(strCommand, vbNormalFocus)
    Else    ' User chose No.
       ' Perform some action.
    End If
End Sub

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: [Tutorial] SHH or Telnet to a device
« Reply #8 on: February 22, 2012, 12:29:33 PM »
well that certainly makes more sense (talking to a simulator). What I would probably do is put a break right at "TaskID = Shell(strCommand, vbNormalFocus)" and display the strCommand to compare it with what you are peforming from the command line. Normally the ip address that user store in a shape is just the ip portion and does not include the port number. There's no reason why it can't be included in the custom properties in that format (port included).
al

d33d3345

  • Newbie
  • *
  • Posts: 6
Re: [Tutorial] SHH or Telnet to a device
« Reply #9 on: February 23, 2012, 09:18:44 AM »
Hi Aledlund,

Any chance you could help me do it?

I'm really not good with this type of thing.

Regards,
John

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: [Tutorial] SHH or Telnet to a device
« Reply #10 on: February 23, 2012, 10:36:37 AM »
well you hi-jacked a thread and didn't include your version of visio and os (it does make a difference)
 ;D
al

d33d3345

  • Newbie
  • *
  • Posts: 6
Re: [Tutorial] SHH or Telnet to a device
« Reply #11 on: February 23, 2012, 05:15:08 PM »
Hi Aledlund,

I really am sorry, that was not my intention, sorry :(

If your still ok to assist, then Im running Visio 2003 at home on Windows Vista. 

I really appreciate your help.

Thanks you,
John

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: [Tutorial] SHH or Telnet to a device
« Reply #12 on: February 23, 2012, 06:45:18 PM »
np,
I'll see what I can do,
al
 :)

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: [Tutorial] SHH or Telnet to a device
« Reply #13 on: February 24, 2012, 07:45:09 AM »
a sllight change to how the macro is called (added port argument), need to change the dblclick event to match, trivial change to the code (clean up definitions, use & where appropriate rather than +)
tested for telnet, works fine
al
you have to sign in to see the attachments
« Last Edit: February 24, 2012, 09:35:38 AM by aledlund »

bghotra

  • Newbie
  • *
  • Posts: 2
Re: [Tutorial] SHH or Telnet to a device
« Reply #14 on: November 15, 2013, 09:47:28 PM »
I'm sorry about replying so late to this message. But I'm ttrying this and it's not working. I am trying the shapesheet way by adding action. I guess my problem is the CALLTHIS("ThisDocument.manageDevice") portion of the actions... can someone give an example how the filename is to be defined please as one of the posts said to make sure ThisDocument is changed to your file name? I would really appreciate it.