I need to make an application that saves the log of a Telnet made to ip 10.123.12.123, to give an example, with a port 1234 for example too.
The problem is that looking at examples I can not understand how the socket class works, I do not know if I'm creating it wrong or not.
The application consists simply of a button, when you press it, it starts the connection and starts saving the log in a text / DB file, I still do not know how I will do it.
I have seen codes and examples but I can not understand what is going on in the program, I do not know if someone could make a simple example of a listener that stores information about a telnet connection.
Thanks in advance.
This is what TELNET returns to me and I need to add those values with dates and so on in a BBDD
The thing is, I write in CMD: Telnet 10.123.12.123 1234
once it enters the server I login with login user password
and once inside I launch the command queueinfo
to return the data of the queues that are in the moment , what I need exactly is that in my program the values that are returned to me are saved to save them in a database with a datetime.now
or some equivalent of it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Windows.Forms;
using System.Threading;
namespace ColasTelnet
{
class TelnetServer
{
public static void conectar()
{
TcpListener server = null;
IPAddress ip = IPAddress.Parse("10.123.12.123");
server = new TcpListener(ip, 1234);
Thread.Sleep(10000);
server.Start();
byte[] bytes = new Byte[256];
String data = null;
while (true)
{
TcpClient client = server.AcceptTcpClient();
data = null;
NetworkStream stream = client.GetStream();
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
MessageBox.Show("Received: {0}", data);
// Process the data sent by the client.
data = data.ToUpper();
byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
// Send back a response.
stream.Write(msg, 0, msg.Length);
MessageBox.Show("Sent: {0}", data);
}
}
}
}
}