-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientInfo.cs
More file actions
51 lines (46 loc) · 1.61 KB
/
ClientInfo.cs
File metadata and controls
51 lines (46 loc) · 1.61 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
namespace LabTracker;
/// <summary>
/// Client information.
/// </summary>
/// <param name="mac">Client MAC address</param>
/// <param name="ip">Client IP address</param>
/// <param name="hostname">Client hostname</param>
/// <param name="idleTime">Client idle time in seconds</param>
public readonly struct ClientInfo(string? mac, string? ip, string? hostname, int? idleTime)
{
public readonly string? Mac { get; } = mac;
public readonly string? Ip { get; } = ip;
public readonly string? Hostname { get; } = hostname;
public readonly int? IdleTime { get; } = idleTime;
public string DisplayName => Hostname ?? Mac ?? "Unknown";
/// <summary>
/// Unique identifier for the client.
/// </summary>
/// <returns>Client identifier string</returns>
public string GetClientId() => Mac ?? "Unknown";
/// <summary>
/// Whether client is considered idle based on max idle time
/// </summary>
/// <param name="maxIdleSeconds">Maximum idle time in seconds</param>
/// <returns>True if client is idle, false otherwise</returns>
public bool IsIdle(int maxIdleSeconds) => IdleTime.HasValue && IdleTime.Value > maxIdleSeconds;
/// <summary>
/// String representation of the client information.
/// </summary>
/// <returns>Formatted string with client details</returns>
public override string ToString()
{
if (Mac == null)
{
return "Unknown Client";
}
else if (!string.IsNullOrEmpty(Hostname))
{
return $"{Mac}({Hostname})";
}
else
{
return Mac;
}
}
}