mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 12:30:55 +00:00
asdasdasd
This commit is contained in:
1 parent
c4182ec609
commit
9905cde527
76 files changed
+2895
-2529
No files matched your search
@@ -0,0 +1,41 @@
|
||||
using CartriX.Api.Interfaces;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace CartriX.Api.Services
|
||||
{
|
||||
public class NetworkService : INetworkService
|
||||
{
|
||||
public async Task<string> GetHostnameAsync(string ipAddress)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ipAddress)) return string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
var hostEntry = await Dns.GetHostEntryAsync(ipAddress);
|
||||
return hostEntry.HostName;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> GetIpAddressAsync(string hostname)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(hostname)) return string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
var hostEntry = await Dns.GetHostEntryAsync(hostname);
|
||||
var ip = hostEntry.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork);
|
||||
|
||||
return ip?.ToString() ?? string.Empty;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user