-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdesktop-client.js
75 lines (70 loc) · 1.98 KB
/
desktop-client.js
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
/// <reference path="C:\Users\liufha\typings\globals\node\index.d.ts" />
var net = require('net');
var host = 'come2see.me';//'10.61.41.49';'127.0.0.1';//填入机器B的IP或者域名,这里测试填的是本地域名
var port = 4020;//填入机器B的提供client连接的端口
var client;
var loc;
//登陆时需要验证身份
var https = require('https');
var fs = require('fs');
var options = {
hostname:host,//'121.201.63.42',
//hostname:'127.0.0.1',
//port:8889,
port:49289,//3088,
path:'/desktop',
method:'GET',
key:fs.readFileSync('./keys/client-key.pem'),
cert:fs.readFileSync('./keys/client-cert.pem'),
ca: [fs.readFileSync('./keys/ca-cert.pem')],
agent:false
};
options.agent = new https.Agent(options);
function auth(){
var req1 = https.request(options,function(res){
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
console.log("statusCode: ", res.statusCode);
res.setEncoding('utf-8');
res.on('data',function(d){
console.log(d);
main();
})
});
req1.end();
req1.on('error',function(e){
console.log(e);
})
}
auth();
function main() {
function connect() {
client = net.connect(port,host, function() {
console.log("代理服务端:"+host+':'+port+' 连接成功!');
loc = net.connect(3389, function() {
console.log('本地远程桌面 3389 连接成功!');
loc.pipe(client);
client.pipe(loc);
});
loc.on('close', function() {
delete(loc);
if(client) client.end();
console.log('local 3389 disconnected');
});
});
client.on('error', function() {
console.log("代理服务端:"+host+':'+port+' 连接失败,正在重试...');//需要重新认证
//auth();
setTimeout(connect,5000);
});
client.on('close', function() {
delete(client);
if(loc)loc.end();
console.log(host+':'+port+' 代理连接已关闭');
setTimeout(connect,100);
});
}
connect();
process.title = '客户端';
return;
}