-
Excel VBA Telnet Client for Remote Connect
We use Telnet Client sessions to control or manage systems that does not have a keyboard or monitor attached to it.
A simple example is the Internet Broadband Router at our home. Similar to that there are lot of network routers, bridges and servers which has to be connected through a Telnet session and operate them.
Network Technicians connect to these devices from remote computer and resolve if there are any issues. Usually these servers will be Unix or Linux based and the commands that you can issue here are some of the basic Unix Commands.
Also Read: Make your Excel Talk
Telnet Commands from Command Prompt
If you have a broadband router at your home, you can try to connect to it with below steps.
- Open a Command Prompt.
- Type ‘Telnet 192.168.1.1’ or ‘Telnet 10.0.0.1’
- Login with user id ‘admin’ and password as ‘password’ or ‘admin’
- Type ‘ps’. This command will show the running processes in the router.
- Type ‘help’ to get a list of supported commands.
Also Read: Login to Facebook, Twitter, Google+ in IE from Excel
How to VBA Telnet from Excel?
When a set of Telnet commands need to be executed on a remote device or server through telnet client session, then this Excel VBA macro code can be used to automate the telnet session.
Download a Sample Excel VBA Telnet Session Downloaded 2,989 Times
This code tried to connect to Telnet server with IP 192.168.1.1. Replace this Server IP address with your Server details and other login credentials. Winsock component will be used to execute this Telnet session.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Visit our website for more Tips and Tricks '' ---- Officetricks.com ---- '' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Sub Start_Telnet_Session()'Declare VariablesDim Data As StringDim Winsock1'Server IP, Port & Login CredentialsTelnetServer = ThisWorkbook.Sheets(1).Cells(1, 1)TelnetPort = ThisWorkbook.Sheets(1).Cells(2, 1)TelnetUser = ThisWorkbook.Sheets(1).Cells(3, 1)TelnetPassword = ThisWorkbook.Sheets(1).Cells(4, 1)TelnetCommands = ThisWorkbook.Sheets(1).Cells(5, 1)'Create WinSock Object & Connect to ServerSet Winsock1 = New MSWinsockLib.WinsockWinsock1.RemoteHost = TelnetServerWinsock1.RemotePort = TelnetPortWinsock1.Connect'Wait Till connection is SuccessDo Until Winsock1.State = 7DoEventsIf Winsock1.State = sckError ThenExit SubEnd IfLoop'Send UserNameWinsock1.SendData TelnetUser & vbCrLfDoEvents: Application.Wait (Now + TimeValue("0:00:05"))'Send Password if you Server Requires oneWinsock1.SendData TelnetPassword & vbCrLfDoEvents: Application.Wait (Now + TimeValue("0:00:05"))'Send Commands One by one & Get response from Serveri = 5While TelnetCommands <> ""DoEvents: Application.Wait (Now + TimeValue("0:00:01"))Winsock1.SendData TelnetCommands & vbCrLfDoEvents: Application.Wait (Now + TimeValue("0:00:05"))'Get ResponseWinsock1.GetData DataData = VBA.Replace(Data, vbLf, "")Data = VBA.Replace(Data, vbCr, vbNewLine)MsgBox Datai = i + 1TelnetCommands = ThisWorkbook.Sheets(1).Cells(i, 1)WendMsgBox "Process Completed - Closing Telnet Connection"Winsock1.CloseEnd Sub
The above code waits for certain time interval (1 second to 5 Seconds) for different operations. Based on the speed of your server, modify this ‘wait time’.This code, not only issue telnet commands to server, but also read data or messages returned by Telnet server or device. This way we can add more automation option by processing the return message and perform different operations accordingly.
More Tips: How to get Folders List and Size
Previous Post: VBA Code – Create Index of Worksheets – with Links to each Sheet
Next Post: 5 Best Facebook Games10 thoughts on “How to use Excel VBA Telnet To Autorun Commands?”
Leave a Reply
You must be logged in to post a comment.
How to use Excel VBA Telnet To Autorun Commands?
Popular Posts
Recent Posts
Similar Pages
Popular Tags
- Block Apps in FaceBook print screen Excel Countif Record Macro Timer in Excel Task Manager VCF HTML Table Import Data Thumbnails Text to Speech TTS Candy Crush C++ Programing Machine learning AI bulk email Excel VBA vba color index vba color codes Android social media Twitter Google+ Google Adsense Tips bitcoin Calendar in Excel outlook vba mass email Data Mining Excel Macro Facebook WhatsApp python Wordpress
Anyway to get this to work for Windows 7
Is it not working in Windows 7?
Please try this in Windows 7 and post the error message or difficulties, that you are facing.
I have tried in Windows 7 and Windows 10 and I have copied in the MSWinsock.ocx and tried to use it however I get a license error when i try to reference it
#1: I guess it is problem with MSWinsock.ocx installation. After copying the ocx file did you try to register it? please check whether OCX is working fine with any other applications.
#2: Is this Code working fine with Windows 7?
Hello,What is the macro passowrd?
I need vbaproject password, many thanks.
Hi, The Excel file is not working in my Microsoft Office 2013. WOuld you please help me?
why making the excel file available for download if its macros are password protected?
Does it contain a virus?
I agree and when I run the file I get a compile error in hidden module: Module1
I have Office 2010 but it doesn’t like MSWinsockLib, any ideas?