Exemplo n.º 1
0
        public Task Disconnect(string id)
        {
            var connection = RasApi32.RasEnumConnections().FirstOrDefault(c => c.Entry.ToString() == id);

            RasApi32.RasHangUp(connection.Handle);

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public Task <IPAddress> GetIpAddress(string id)
        {
            var connection = RasApi32.RasEnumConnections().FirstOrDefault(c => c.Entry.ToString() == id);

            if (connection.Handle == IntPtr.Zero)
            {
                return(Task.FromResult(IPAddress.None));
            }

            var status = RasApi32.RasGetProjectionInfo(connection.Handle);

            return(Task.FromResult(IPAddress.Parse(status.IpAddress)));
        }
Exemplo n.º 3
0
        public Task <VpnStatus> GetStatus(string id)
        {
            var connection = RasApi32.RasEnumConnections().FirstOrDefault(c => c.Entry.ToString() == id);

            if (connection.Handle == IntPtr.Zero)
            {
                return(Task.FromResult(VpnStatus.Disconnected));
            }

            var status = RasApi32.RasGetConnectStatus(connection.Handle);

            switch (status.State)
            {
            case RasConnState.Connected:
                return(Task.FromResult(VpnStatus.Connected));

            case RasConnState.Disconnected:
                return(Task.FromResult(VpnStatus.Disconnecting));

            default:
                return(Task.FromResult(VpnStatus.Connecting));
            }
        }