-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add route to give information about machine
- Loading branch information
Showing
4 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Net; | ||
using System.Net.NetworkInformation; | ||
|
||
namespace OrangeFinance.Endpoints; | ||
|
||
public static class Info | ||
{ | ||
public static void RegisterInfoEndpoints(this IEndpointRouteBuilder routes) | ||
{ | ||
var farms = routes.MapGroup("/info"); | ||
|
||
farms.MapGet("", async () => | ||
{ | ||
var machineName = Environment.MachineName; | ||
var osVersion = Environment.OSVersion.ToString(); | ||
var ipAddress = GetLocalIPAddress(); | ||
var macAddress = GetMacAddress(); | ||
var processId = Environment.ProcessId; | ||
|
||
return (new | ||
{ | ||
MachineName = machineName, | ||
OSVersion = osVersion, | ||
IPAddress = ipAddress, | ||
MacAddress = macAddress, | ||
ProcessId = processId, | ||
Timestamp = DateTime.UtcNow | ||
}); | ||
|
||
string GetLocalIPAddress() | ||
{ | ||
string localIP = "N/A"; | ||
var host = Dns.GetHostEntry(Dns.GetHostName()); | ||
foreach (var ip in host.AddressList) | ||
{ | ||
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) | ||
{ | ||
localIP = ip.ToString(); | ||
break; | ||
} | ||
} | ||
return localIP; | ||
} | ||
|
||
string GetMacAddress() | ||
{ | ||
return NetworkInterface.GetAllNetworkInterfaces() | ||
.Where(nic => nic.OperationalStatus == OperationalStatus.Up) | ||
.Select(nic => nic.GetPhysicalAddress().ToString()) | ||
.FirstOrDefault() ?? "N/A"; | ||
} | ||
|
||
}).Produces(statusCode: 200) | ||
.MapToApiVersion(1) | ||
.WithOpenApi(); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters