forked from NetCoreStack/Proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultProxyContextFilter.cs
More file actions
31 lines (27 loc) · 900 Bytes
/
Copy pathDefaultProxyContextFilter.cs
File metadata and controls
31 lines (27 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Net;
using System.Net.Sockets;
namespace NetCoreStack.Proxy.Internal
{
public class DefaultProxyContextFilter : IProxyContextFilter
{
public const string NetCoreStackUserAgent = "NetCoreStack-Proxy-UserAgent";
public readonly static string LocalIpAddress = GetLocalIPAddress();
public static string GetLocalIPAddress()
{
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
return string.Empty;
}
public void Invoke(ProxyContext proxyContext)
{
proxyContext.ClientIp = LocalIpAddress;
proxyContext.UserAgent = NetCoreStackUserAgent;
}
}
}