-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
129 lines (115 loc) · 4.75 KB
/
Copy pathProgram.cs
File metadata and controls
129 lines (115 loc) · 4.75 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Threading.Tasks;
namespace ZTEModem
{
class Program
{
static async Task Main(string[] args)
{
Console.Title = "ZTE Modem - Rebooter";
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("----------------------");
Console.ResetColor();
Console.WriteLine("> Loading configuration...");
var donotask = false;
foreach (string arg in args)
{
if (string.IsNullOrWhiteSpace(arg)) continue;
if (arg.ToLower() == "/f")
{
donotask = true;
break;
}
}
var cm = new ConfigManager();
Console.Write(" Router : ");
var router = cm.GetString(ConfigManager.KEY_ROUTER);
if (string.IsNullOrWhiteSpace(router))
{
router = askInput(" Router : ");
cm.SetString(ConfigManager.KEY_ROUTER, router);
}
else Console.WriteLine(router);
Console.Write(" Username : ");
var username = cm.GetString(ConfigManager.KEY_USERNAME);
if (string.IsNullOrWhiteSpace(username))
{
username = askInput(" Username : ");
cm.SetString(ConfigManager.KEY_USERNAME, username);
}
else Console.WriteLine(username);
Console.Write(" Password : ");
var password = cm.GetString(ConfigManager.KEY_PASSWORD);
if (string.IsNullOrWhiteSpace(password))
{
password = askInput(" Password : ", true);
cm.SetString(ConfigManager.KEY_PASSWORD, password);
}
else Console.WriteLine(password.ToAsterisk());
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("\n----------------------");
Console.ResetColor();
var modem = new Modem(router);
Console.WriteLine("> Login to router...");
var login = await modem.Login(username, password);
Console.WriteLine(" Login Status : " + (login ? "OK" : "FAILED"));
if (!login) PressAnyKeyToExit();
Console.WriteLine();
Console.WriteLine("> Get device info...");
var device = await modem.GetDeviceInfo();
Console.WriteLine(" Model : " + device.Model);
Console.WriteLine(" Serial Number : " + device.SerialNumber);
Console.WriteLine(" Hardware Version : " + device.HardwareVersion);
Console.WriteLine(" Software Version : " + device.SoftwareVersion);
Console.WriteLine(" Bootloader Version : " + device.BootloaderVersion);
Console.WriteLine(" Pon Serial Number : " + device.PonSerialNumber);
Console.WriteLine(" Batch Number : " + device.BatchNumber);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("> Reboot the device? [Y/n] : ");
Console.ResetColor();
var todo = donotask ? ConsoleKey.Y : Console.ReadKey().Key;
if (todo == ConsoleKey.Y || todo == ConsoleKey.Enter)
{
Console.SetCursorPosition(0, Console.CursorTop);
Console.WriteLine("> Rebooting device... ");
await modem.Reboot();
}
else
{
Console.SetCursorPosition(0, Console.CursorTop);
Console.ForegroundColor = ConsoleColor.Red;
Console.ResetColor();
Console.WriteLine("> Cancel rebooting the device...");
}
modem.Close();
PressAnyKeyToExit();
}
static string askInput(string question, bool protect = false)
{
while (true)
{
var input = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(input))
{
if (protect)
{
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(question + input.ToAsterisk());
}
return input;
}
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(question);
}
}
static void PressAnyKeyToExit()
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("\n----------------------");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Press any key to exit...");
Console.ReadKey();
}
}
}