|
@@ -1,6 +1,7 @@
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
+using System.Data.Entity.Core.Common.EntitySql;
|
|
|
using System.Net;
|
|
|
using System.Net.Http;
|
|
|
using System.Net.WebSockets;
|
|
@@ -75,9 +76,33 @@ public class WebsocketService<T> where T : WsSession
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- var ipaddress = context.Connection.RemoteIpAddress;
|
|
|
- var port = context.Connection.RemotePort;
|
|
|
- data.Endpoint = new IPEndPoint(ipaddress, port);
|
|
|
+ var proxyPassClientIp = context.Request.Headers["X-Forwarded-For"];
|
|
|
+ foreach (var infoString in proxyPassClientIp)
|
|
|
+ {
|
|
|
+ foreach (var testIp in infoString.Split(','))
|
|
|
+ {
|
|
|
+ logger.LogDebug("X-Forwarded-For {ip}", testIp);
|
|
|
+ if (IPEndPoint.TryParse(testIp, out var parseResult) &&
|
|
|
+ (parseResult.AddressFamily is System.Net.Sockets.AddressFamily.InterNetwork or System.Net.Sockets.AddressFamily.InterNetworkV6)
|
|
|
+ )
|
|
|
+ {
|
|
|
+ data.Endpoint = parseResult;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data.Endpoint != null)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data.Endpoint is null)
|
|
|
+ {
|
|
|
+ var ipaddress = context.Connection.RemoteIpAddress;
|
|
|
+ var port = context.Connection.RemotePort;
|
|
|
+ data.Endpoint = new IPEndPoint(ipaddress, port);
|
|
|
+ }
|
|
|
}
|
|
|
catch
|
|
|
{
|