From 1dba38fb693c3d57bb3ba96bb007b2926d0e5e72 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 29 Oct 2023 19:12:24 +0530 Subject: [PATCH] Extensions: implemented GetLocalIpAddress(). --- DnsServerCore/Extensions.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/DnsServerCore/Extensions.cs b/DnsServerCore/Extensions.cs index e3590a92..b2ebaf69 100644 --- a/DnsServerCore/Extensions.cs +++ b/DnsServerCore/Extensions.cs @@ -61,6 +61,25 @@ namespace DnsServerCore } } + public static IPAddress GetLocalIpAddress(this HttpContext context) + { + try + { + IPAddress localIP = context.Connection.LocalIpAddress; + if (localIP is null) + return IPAddress.Any; + + if (localIP.IsIPv4MappedToIPv6) + localIP = localIP.MapToIPv4(); + + return localIP; + } + catch + { + return IPAddress.Any; + } + } + public static UserSession GetCurrentSession(this HttpContext context) { if (context.Items["session"] is UserSession userSession)