-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
124 lines (113 loc) · 6.8 KB
/
Program.cs
File metadata and controls
124 lines (113 loc) · 6.8 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Zyxel.ZyxelAPI;
namespace Zyxel
{
class Program
{
public enum TypeR : byte
{
AllMy,
NotMy,
Input,
Output,
All,
}
public static Table t = new Table();
static void Main(string[] args)
{
Parser p = new Parser(args);
if (p.FindParams("--help"))
{
Console.WriteLine("Zyxel. Менеджер текущий соеденений");
Console.WriteLine("Ключи запуска:");
Console.WriteLine("-P Показывать ли исходящий порт (не обязательно)");
Console.WriteLine("-d Адрес до роутера");
Console.WriteLine("-l Логин");
Console.WriteLine("-p Пароль");
Console.WriteLine("-t Время обновления (в миллисекундах)");
Console.WriteLine("-i Локальный IP адрес (не обязательно)");
Console.WriteLine("-w Опасные порты, через запятую (не обязательно)");
Console.WriteLine("Комманды в работе:");
Console.WriteLine("E Выход");
Console.WriteLine("I Просмотр входящих подключений");
Console.WriteLine("A Просмотр всех подключений");
Console.WriteLine("P Пауза обновлений");
Console.WriteLine("S Сохранить лог");
}
else
{
bool Correct = false;
bool Running = true;
bool Pause =! true;
bool SP = p.FindParams("-P");
string[] WP = p.FindParamsAndArgs("-w", out Correct).Split(',');
TypeR type = TypeR.All;
ZyxelAPI.ZyxelAPI z = new ZyxelAPI.ZyxelAPI(p.FindParamsAndArgs("-d", out Correct), p.FindParamsAndArgs("-l", out Correct), p.FindParamsAndArgs("-p", out Correct));
t.AddTitle("#", "Источник", "Назначение", "Сервис/порт", "Размер");
Console.WriteLine("Соеденение с {0}. Логин {1} Пароль {2}.", z.URL, z.Login, z.Password);
while (!Console.TreatControlCAsInput & Running)
{
if (Console.KeyAvailable)
{
var key = Console.ReadKey().Key;
if (key == ConsoleKey.E)
Running = false;
else if (key == ConsoleKey.I)
type = TypeR.Input;
else if (key == ConsoleKey.O)
type = TypeR.Output;
else if (key == ConsoleKey.A)
type = TypeR.All;
else if (key == ConsoleKey.P)
Pause = !Pause;
else if (key == ConsoleKey.S)
System.IO.File.WriteAllText(Environment.CurrentDirectory + "//" + DateTime.Now.ToString().Replace(':', '-') + ".txt", t.Data);
Console.Beep(637, 1000);
}
if (!Pause)
{
XmlNode xml = z.GetConnection();
t.Clear();
for (int i = 0; i < xml.ChildNodes.Count; i++)
{
if (type == TypeR.All)
t.AddLine(i.ToString(),
xml.ChildNodes.Item(i).SelectSingleNode("src").InnerText,
xml.ChildNodes.Item(i).SelectSingleNode("dst").InnerText,
xml.ChildNodes.Item(i).SelectSingleNode("protocol").InnerText + "/" + (SP ? xml.ChildNodes.Item(i).SelectSingleNode("sport").InnerText + "-" : "") + xml.ChildNodes.Item(i).SelectSingleNode("dport").InnerText,
FileSize.Calculate(xml.ChildNodes.Item(i).SelectSingleNode("bytes").InnerText));
else if (type == TypeR.Input)
if (!IPManager.IsLANIP(xml.ChildNodes.Item(i).SelectSingleNode("src").InnerText) & xml.ChildNodes.Item(i).SelectSingleNode("src").InnerText != p.FindParamsAndArgs("-i", out Correct))
t.AddLine(i.ToString(),
xml.ChildNodes.Item(i).SelectSingleNode("src").InnerText,
xml.ChildNodes.Item(i).SelectSingleNode("dst").InnerText,
xml.ChildNodes.Item(i).SelectSingleNode("protocol").InnerText + "/" + (SP ? xml.ChildNodes.Item(i).SelectSingleNode("sport").InnerText + "-" : "") + xml.ChildNodes.Item(i).SelectSingleNode("dport").InnerText,
FileSize.Calculate(xml.ChildNodes.Item(i).SelectSingleNode("bytes").InnerText));
else if (type == TypeR.Output)
if (IPManager.IsLANIP(xml.ChildNodes.Item(i).SelectSingleNode("src").InnerText) || xml.ChildNodes.Item(i).SelectSingleNode("src").InnerText == p.FindParamsAndArgs("-i", out Correct))
t.AddLine(i.ToString(),
xml.ChildNodes.Item(i).SelectSingleNode("src").InnerText,
xml.ChildNodes.Item(i).SelectSingleNode("dst").InnerText,
xml.ChildNodes.Item(i).SelectSingleNode("protocol").InnerText + "/" + (SP ? xml.ChildNodes.Item(i).SelectSingleNode("sport").InnerText + "-" : "") + xml.ChildNodes.Item(i).SelectSingleNode("dport").InnerText,
FileSize.Calculate(xml.ChildNodes.Item(i).SelectSingleNode("bytes").InnerText));
}
t.Print(WP);
}
if (!Pause)
{
System.Threading.Thread.Sleep(int.Parse(p.FindParamsAndArgs("-t", out Correct)));
Console.BackgroundColor = ConsoleColor.Black;
}
else
{
Console.BackgroundColor = ConsoleColor.Red;
}
}
}
}
}
}