-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
70 lines (58 loc) · 2.21 KB
/
Program.cs
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
using System;
using System.Threading;
using Renci.SshNet;
namespace ssh_proxy
{
class Program
{
static void Main(string[] args)
{
string host = "8.8.8.8";
string user = "root";
string password = "root_password";
using (var client = new SshClient(host, 22, user, password)) // Connect to server
{
try
{
client.Connect();
Console.WriteLine("Connected!");
//Console.WriteLine("update");
var cmd = client.RunCommand("apt-get update -y");
//Console.WriteLine("install git");
cmd = client.RunCommand("apt-get install git -y");
//Console.WriteLine("clone repository");
cmd = client.RunCommand("git clone https://github.com/Zeddex/proxy.git");
//Console.WriteLine("install main script");
cmd = client.RunCommand("cd proxy && chmod +x proxy.sh && bash proxy.sh");
Console.WriteLine("reboot...");
try
{
cmd = client.CreateCommand("reboot");
cmd.Execute();
}
catch { }
Thread.Sleep(30000);
while (!client.IsConnected) // check server is online again
{
Thread.Sleep(1000);
try
{
client.Connect();
}
catch {}
}
Console.WriteLine("Connected!");
Console.WriteLine(client.ConnectionInfo.ServerVersion);
client.Disconnect();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
Console.WriteLine("Done!");
Console.ReadLine();
}
}
}