Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (56 loc) · 1.44 KB
/
Copy pathProgram.cs
File metadata and controls
73 lines (56 loc) · 1.44 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
using Org.BouncyCastle.Asn1.Cms;
using Renci.SshNet;
using System.IO;
string logDirectory = "logs";
if (args.Length == 1 && args[0].ToLower() == "clear")
{
if (Directory.Exists(logDirectory))
{
string[] files = Directory.GetFiles(logDirectory);
foreach (string file in files)
{
File.Delete(file);
}
Console.WriteLine($"{files.Length} fichiers de log sont supp");
}
else
{
Console.WriteLine("Aucun fichier");
}
return;
}
if (!Directory.Exists(logDirectory))
{
Directory.CreateDirectory(logDirectory);
}
string username;
string ip;
string password;
string date = DateTime.Now.ToString("dd.MM.yyyy");
string hour = DateTime.Now.ToString("HH-mm-ss");
if (args.Length >= 3)
{
username = args[0];
ip = args[1];
password = args[2];
}
else
{
Console.Write("nom d'utilisateur: ");
username = Console.ReadLine();
Console.Write("ip : ");
ip = Console.ReadLine();
Console.Write("mdp : ");
password = Console.ReadLine();
}
Console.WriteLine($"Connexion a {ip}...\n\n");
using (var client = new SshClient(ip, username, password))
{
client.Connect();
using SshCommand cmd = client.RunCommand("fastfetch");
Console.Clear();
string fileName = $"result_{username}_{date}_{hour}.txt";
string fullPath = Path.Combine(logDirectory, fileName);
File.WriteAllText(fullPath, cmd.Result);
Console.WriteLine($"{fullPath}");
}