Log Real IP on Authentication failure in case of a reverse proxy

closes #3711
This commit is contained in:
Taloth Saldono
2020-04-27 23:58:35 +02:00
committed by Qstick
parent e8018b7959
commit 7afea3df90
3 changed files with 76 additions and 21 deletions

View File

@@ -1,29 +1,40 @@
using System.Net;
using System.Net;
using System.Net.Sockets;
namespace NzbDrone.Common.Extensions
namespace NzbDrone.Common.Extensions
{
public static class IPAddressExtensions
{
public static bool IsLocalAddress(this IPAddress ipAddress)
{
if (ipAddress.ToString() == "::1")
if (ipAddress.IsIPv6LinkLocal)
{
return true;
}
byte[] bytes = ipAddress.GetAddressBytes();
switch (bytes[0])
if (IPAddress.IsLoopback(ipAddress))
{
case 10:
case 127:
return true;
case 172:
return bytes[1] < 32 && bytes[1] >= 16;
case 192:
return bytes[1] == 168;
default:
return false;
return true;
}
if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
{
byte[] bytes = ipAddress.GetAddressBytes();
switch (bytes[0])
{
case 10:
case 127:
return true;
case 172:
return bytes[1] < 32 && bytes[1] >= 16;
case 192:
return bytes[1] == 168;
default:
return false;
}
}
return false;
}
}
}