public int GetProcessId(ProxyEndPoint endPoint) { if (processId.HasValue) { return(processId.Value); } if (RunTime.IsWindows) { var remoteEndPoint = (IPEndPoint)RemoteEndPoint; // If client is localhost get the process id if (NetworkHelper.IsLocalIpAddress(remoteEndPoint.Address)) { processId = TcpHelper.GetProcessIdByLocalPort(endPoint.IpAddress.AddressFamily, remoteEndPoint.Port); } else { // can't access process Id of remote request from remote machine processId = -1; } return(processId.Value); } throw new PlatformNotSupportedException(); }
protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint, CancellationTokenSource cancellationTokenSource, Request request) : this(server, endPoint, cancellationTokenSource) { CancellationTokenSource = cancellationTokenSource; ProxyClient = new ProxyClient(); WebSession = new HttpWebClient(request); LocalEndPoint = endPoint; WebSession.ProcessId = new Lazy <int>(() => { if (RunTime.IsWindows) { var remoteEndPoint = ClientEndPoint; // If client is localhost get the process id if (NetworkHelper.IsLocalIpAddress(remoteEndPoint.Address)) { var ipVersion = endPoint.IpV6Enabled ? IpVersion.Ipv6 : IpVersion.Ipv4; return(TcpHelper.GetProcessIdByLocalPort(ipVersion, remoteEndPoint.Port)); } // can't access process Id of remote request from remote machine return(-1); } throw new PlatformNotSupportedException(); }); }