-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
88 lines (78 loc) · 2.95 KB
/
Copy pathProgram.cs
File metadata and controls
88 lines (78 loc) · 2.95 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
using CommandLine;
namespace MiniHping;
/// <summary>
/// Main program class for MiniHping, an educational network tool for sending TCP/ICMP packets.
/// </summary>
class Program
{
/// <summary>
/// Main entry point for the MiniHping application.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
static async Task<int> Main(string[] args)
{
Console.WriteLine("MiniHping v0.1.0 - by z0rimo");
Console.WriteLine("==========================================");
return await Parser.Default.ParseArguments<Options>(args)
.MapResult(
async (Options opts) => await RunProgram(opts),
errs => Task.FromResult(1)
);
}
/// <summary>
/// Main program logic to run MiniHping with the provided options.
/// </summary>
/// <param name="opts"></param>
/// <returns></returns>
static async Task<int> RunProgram(Options opts)
{
try
{
// 1. 시스템 체크
if (!NetworkManager.CheckSystemRequirements())
return 1;
// 2. 네트워크 인터페이스 선택
var device = NetworkManager.SelectNetworkInterface(opts.InterfaceIndex);
if (device == null)
{
Console.WriteLine("❌ Failed to select network interface");
return 1;
}
// 3. 대상 IP 주소 해석
var targetIP = await NetworkManager.ResolveHostnameAsync(opts.Target);
if (targetIP == null)
{
Console.WriteLine($"❌ Cannot resolve hostname '{opts.Target}'");
return 1;
}
// 4. 정보 출력
Console.WriteLine($"Target: {opts.Target} ({targetIP})");
Console.WriteLine($"Mode: {opts.Mode.ToUpper()}");
if (opts.Mode.Equals("tcp", StringComparison.OrdinalIgnoreCase))
Console.WriteLine($"Port: {opts.Port}");
Console.WriteLine($"Interface: {device.Name}");
Console.WriteLine($"Packets: {(opts.Count == -1 ? "unlimited" : opts.Count.ToString())}");
Console.WriteLine();
// 5. 서비스 시작
var hpingService = new HpingService(device);
if (opts.Mode.Equals("tcp", StringComparison.OrdinalIgnoreCase))
await hpingService.StartTcpHpingAsync(targetIP, opts);
else if (opts.Mode.Equals("icmp", StringComparison.OrdinalIgnoreCase))
await hpingService.StartIcmpHpingAsync(targetIP, opts);
else
{
Console.WriteLine($"❌ Unsupported mode: {opts.Mode}");
return 1;
}
return 0;
}
catch (Exception ex)
{
Console.WriteLine($"❌ Error: {ex.Message}");
if (opts.Verbose)
Console.WriteLine($"Stack trace: {ex.StackTrace}");
return 1;
}
}
}