Writing a Visual Basic 2008 Telnet Client Part 1

General Networking > VB Telnet Part 1
Wednesday, 24th February 2010

Recently I had a requirement to control a router from within a program. It was to simplify VOIP, though the reasons are irrelevent for this article. I had done similar things in the past in VB6, but thats gone the way of the Dodo now. So the first thing to do was get an up-to-date language. Luckily, Microsoft now give away Visual Basic for free! You can use the link below to download a copy from their site.

Download VB 2008 Express from the Microsoft Site.

So I downloaded and installed VB2008, and fired it up. To start with I thought I would keep it simple, and write a (very) basic telnet client, just so that I could easily test that things were working. Unfortunately, VB2008 doesn't handle sockets in the same way that VB6 used to, so I had to work out what the correct method was.

I am still looking for the correct method! I scoured countless forums, help pages and blogs. There are loads of people looking for advice on telnet via vb, but nobody providing a simple solution that doesn't involving buying a third party tool. I did however find a snippet of code which looked promising, so I threw it into VB to see what would happen. I ended up with a functioning, if bodged, telnet client. From there it was a simple matter to write a routine which controlled the VOIP on the router without the aid of a GUI.

Now, I'm not a VB expert. PHP is my game. So the code I ended up with is a bit of a bodge, and I don't know what bits of it actually do. However, taken as a whole, I know it works. On that basis, I am documenting my workings here, for two reasons:

  • Anybody looking for a hands-on guide to telnet via visual basic will at least get a procedure that produces results
  • Anybody who actually knows what they are talking about might be able to offer improvements / explain the hard bits

So lets get down to business.

1. Fire up VB 2008 and create a project called MyTel, as shown below.

Telnet with VB 2008 Part 1

2. Create a form to look like the one below. We need two text boxes for the IP address and port. A third to enter commands, and a fourth to display results. Use your own img for a logo or omit it altogether. The logo is unimportant. I just like doing shiny buttons. Assign the properties shown in the table below to the assorted controls. If you keep the names identical you will be able to drop the code given later straight in, so don't skimp on the detail.

Telnet with VB 2008 Part 2

I have only listed the important parameters. The size of each individual element is entirely up to you. The layout can be different too, provided all the controls are actually present.

Form:
	(Name):		frmMain
	Text:		MyTel

Text boxes:
1. 	(Name): 	txtIP
	Text: 		192.168.1.1

2.	(Name):		txtPort
	Text:		23

3.	(Name):		txtCommand
	Text:	
	Enabled:	False
	Font:		Courier New, 8pt

4	(Name):		txtResponse
	Text:
	Enabled:	False
	Font:		Courier New, 8pt
	Scrollbars:	Both


Buttons:
1.	(Name):		cmdConnect

2.	(Name):		cmdSend
	Enable:		False

Timer:
1	(Name):		timResponse
	Enable:		True

3. Once you have done this, add the following code to the click event of the CONNECT button.

Telnet with VB 2008 Part 3

If you try running this, you should get a dialog box, with the bottom two text boxes disabled. If you click on CONNECT they should now be enabled. In part 2 we will add some functionality, because fun though it is, our app doesn't do much at the moment!

Writing a Visual Basic 2008 Telnet Client Part 2
Share this:
Share this on Facebook! Tweet this! Share this on Stumbleupon! Share this on Reddit! Digg this! Share this on Delicious!
Next Article >> VB Telnet Part 2
Windows 7 Dongles << Previous Article

The Folowing Comments Have Been Made

On Wed, 31 Mar 2010 05:52:39 +0200, mpchester said:

I have made an alteration to your program if you are interested. I have it set more for my server, but a few changes that you may be interested are .....

Checking for \n just incase they don't send data in separate lines.<br /> Some error handling so that it tells you if it can't connect.<br /> When it disconnects, it will clear out all the variables so you can re-connect or connect to something new.<br /> BUT MOST IMPORTANTLY ... it works without that timer.

Thank you for this article! it helped me A LOT!!!

On Wed, 31 Mar 2010 05:54:34 +0200, mpchester said:

Oh and most importantly, my cantact info is xxxxx@xxxxx.com (please delete this so i don't get tooo spammed)

 

Enter your comments below

All fields are mandatory.

Anti-spam measure.
Stop spamming!

To keep our site free from spam, all comments are moderated prior to publishing. Your comment will be read by one of our staff, and provided it is not blatant advertising, rude or against the spirit of our site, we will do our best to ensure it will appear within one business day. Should you have any specific questions about any item, you should use the Contact page to get in touch instead.

 

Puzbie LTD: Writing a Visual Basic 2008 Telnet Client Part 1
Home    Sitemap    Terms and Conditions    Surprise Me