Exemplo n.º 1
0
        public static EndPoint QuerySessionInformationForEndPoint(int sessionId)
        {
            int retLen;
            var remoteAddress = new WINSTATIONREMOTEADDRESS();

            if (
                WinStationQueryInformationRemoteAddress(IntPtr.Zero, sessionId,
                                                        WINSTATIONINFOCLASS.WinStationRemoteAddress,
                                                        ref remoteAddress,
                                                        Marshal.SizeOf(typeof(WINSTATIONREMOTEADDRESS)),
                                                        out retLen) != 0)
            {
                var ipAddress = ExtractIPAddress(remoteAddress.Family, remoteAddress.Address);
                int port      = ntohs((ushort)remoteAddress.Port);
                return(ipAddress == null ? null : new IPEndPoint(ipAddress, port));
            }
            throw new Win32Exception();
        }
Exemplo n.º 2
0
 static extern int WinStationQueryInformationRemoteAddress(IntPtr hServer, int sessionId,
                                                           WINSTATIONINFOCLASS information,
                                                           ref WINSTATIONREMOTEADDRESS buffer,
                                                           int bufferLength, out int returnedLength);