Overview
This article will demonstrate how to use rexec in .NET using Telnet Factory for .NET.
Code Example
Download TelnetLicense.txt
| Download RE.cs
| Download RE.vb
1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using Jscape.Telnet;
5: using Jscape.Telnet.Options;
6:
7: namespace Rexec_NET
8: {
9: class RE
10: {
11: Rexec r = null;
12: public RE(string hostname, string username,
13: string password, string cmd)
14: {
15: r = new Rexec(hostname, username, password, cmd);
16: }
17:
18: public string execute()
19: {
20: byte[] response = r.Execute();
21: return r.Encoding.GetString(response);
22: }
23:
24: static void Main(string[] args)
25: {
26: try
27: {
28: RE re = new RE("hostname", "user", "pass", "cmd");
29: string response = re.execute();
30: Console.WriteLine(response);
31: }
32: catch (Exception e)
33: {
34: Console.WriteLine(e.Message);
35: }
36:
37: Console.WriteLine("Press any key to continue ... ");
38: Console.Read();
39: }
40: }
41: }
Lines 1-5 : Necessary import statements.
Lines 11-16 : Initialize Rexec instance.
Lines 18-22 : Execute command and get response.
Lines 28 : Initialize RE instance.
Comments