// 通用库
namespace Common
{
const char PS1[] = "EXPECT:";
// 连接类型
enum Enum_Conn_Type
{
SU = 0,
SSH = 1,
TELNET = 2
};
// 匹配类别
enum Enum_Match_Type
{
MATCH_SUCC = 0,
MATCH_FAIL = 1,
MATCH_REPLY = 2
};
// 匹配信息
typedef struct MatchInfo
{
exp_type expType;
string strMatch;
string strReply;
}*PMatchInfo;
// 登录信息
typedef struct LoginInfo
{
Enum_Conn_Type eConType;
string strAddr;
string strUser;
string strPwd;
}*PLoginInfo;
class CRemoteExec
{
public:
CRemoteExec();
virtual ~CRemoteExec();
public:
// 连接远程主机
bool Connect(const PLoginInfo pLoginInfo, const PMatchInfo pMatchSucc,
const PMatchInfo pMatchFail, const PMatchInfo pMatchReply = NULL);
// 执行命令
bool ExecOrder(const string& strOrder);
// 匹配命令返回
bool GetMatchInfo(const PMatchInfo pMatchSucc, const PMatchInfo pMatchFail, const PMatchInfo pMatchReply = NULL);
// 获取匹配字符串
std::string GetMatch();
// 获取连接PID
pid_t GetExpPid();
// 获取错误码
int GetErrorCode();
// 设置超时时间
void SetTimeout(unsigned int nTimeout);
// 关闭连接
void Close();
private:
int m_fd;
int m_iErrorCode;
Tcl_Interp* m_pTcl;
std::string m_strMatch;
};
}
CRemoteExec远程执行类
最新推荐文章于 2023-08-24 15:22:33 发布