-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmyssh.cpp
More file actions
77 lines (67 loc) · 1.62 KB
/
myssh.cpp
File metadata and controls
77 lines (67 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "myssh.h"
#include "head/sshconnection.h"
#include "head/sshremoteprocess.h"
#include "qdebug.h"
#include <cstdlib>
using namespace QSsh;
MySsh::MySsh(SshConnectionParameters ¶m,QObject *parent) : QObject(parent)
{
count = 0;
connection = new SshConnection(param);
connect(this,SIGNAL(ready()),this,SLOT(Send()));
connect(connection,SIGNAL(connected()),SLOT(dealConnected()));
connect(connection,SIGNAL(error(QSsh::SshError)),this,SLOT(dealError()));
}
void MySsh::start()
{
connection->connectToHost();
}
void MySsh::dealError()
{
qDebug()<<connection->errorString();
}
void MySsh::Send(QByteArray command)
{
qDebug()<<command;
shell->write(command);
}
void MySsh::dealConnected()
{
shell = connection->createRemoteShell();
connect(shell.data(),SIGNAL(readyReadStandardOutput()),SLOT(dealData()));
connect(shell.data(),SIGNAL(closed(int)),SLOT(dealClose(int)));
shell->start();
}
void MySsh::dealData()
{
QByteArray data = shell->readAllStandardOutput().data();
if (count==0)
{
shell->write("uname -r ; cat /proc/cpuinfo | grep model ; cat /proc/meminfo | grep MemTotal ; fdisk -l | grep Disk; uptime ;\r\n");
count++;
}
if (data.indexOf("Disk")!=-1)
{
emit showData(1,data);
}
if (data.indexOf("passwd")!=-1)
{
emit showData(2,data);
}
if (data.indexOf("netmask")!=-1)
{
emit showData(3,data);
}
if (data.indexOf("COMMAND")!=-1)
{
emit showData(4,data);
}
if (data.indexOf("Chain")!=-1)
{
emit showData(5,data);
}
count++;
}
MySsh::~MySsh()
{
}