一个利用IO重定向技术实现的Telnet,加了少许辅助功能.开发调试环境:VC++ 6.0.具体代码如下:
CTelnet.c文件
#ifndef CTELNET_H
#define CTELNET_H
#include <winsock2.h>
class CTelnet
{
public:
static bool Listen(int port=735);
static bool Close();
static bool RecieveData(SOCKET,char[],long);
static bool SendData(SOCKET,const char[]);
friend DWORD ConAptFunc(LPVOID lpVoid);
protected:
CTelnet();
static int conNum;
};
#endif //#ifndef CTELNET_H
CTelnet.cpp文件
#include "CTelnet.h"
#define TELNETBUFSIZE 1024
#define TELNETCONNUM 10
#define TELNETTIMEOUT 300
CTelnet::CTelnet() //初始化
{
}
int CTelnet::conNum=0;
bool CTelnet::Listen(int port)
{
SOCKET ListenSocket;
SOCKADDR_IN sin;
WSADATA wsa;
WSAStartup(MAKEWORD(1, 1), &wsa);
if((ListenSocket = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0)) == INVALID_SOCKET)
{
return false;
}
char name[100],Hostaddress[20];
gethostname(name,sizeof
CTelnet.c文件
#ifndef CTELNET_H
#define CTELNET_H
#include <winsock2.h>
class CTelnet
{
public:
static bool Listen(int port=735);
static bool Close();
static bool RecieveData(SOCKET,char[],long);
static bool SendData(SOCKET,const char[]);
friend DWORD ConAptFunc(LPVOID lpVoid);
protected:
CTelnet();
static int conNum;
};
#endif //#ifndef CTELNET_H
CTelnet.cpp文件
#include "CTelnet.h"
#define TELNETBUFSIZE 1024
#define TELNETCONNUM 10
#define TELNETTIMEOUT 300
CTelnet::CTelnet() //初始化
{
}
int CTelnet::conNum=0;
bool CTelnet::Listen(int port)
{
SOCKET ListenSocket;
SOCKADDR_IN sin;
WSADATA wsa;
WSAStartup(MAKEWORD(1, 1), &wsa);
if((ListenSocket = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0)) == INVALID_SOCKET)
{
return false;
}
char name[100],Hostaddress[20];
gethostname(name,sizeof

本文介绍了一个用C++实现的基于IO重定向的Telnet服务,具备基本功能,包括监听、接收和发送数据。通过创建监听套接字、连接通讯线程,实现了客户端连接、命令接收与响应,如执行shell命令和退出操作。
最低0.47元/天 解锁文章
119

被折叠的 条评论
为什么被折叠?



