public Task Disconnect(string id) { var connection = RasApi32.RasEnumConnections().FirstOrDefault(c => c.Entry.ToString() == id); RasApi32.RasHangUp(connection.Handle); return(Task.CompletedTask); }
public Task <Vpn[]> GetVpns() { return(Task.FromResult(( from name in RasApi32.RasEnumEntries() let entry = RasApi32.RasGetEntryProperties(name.EntryName, name.PhonebookPath) where entry.DeviceType.ToLower() == "vpn" select new Vpn(entry.Id.ToString(), name.EntryName)) .ToArray())); }
public Task Connect(string id) { var entryName = RasApi32.RasEnumEntries() .FirstOrDefault(n => RasApi32.RasGetEntryProperties(n.EntryName, n.PhonebookPath).Id.ToString() == id); var dialParams = RasApi32.RasGetEntryDialParams(entryName.EntryName, entryName.PhonebookPath); RasApi32.RasDial(dialParams, entryName.PhonebookPath, (message, state, error) => { }); return(Task.CompletedTask); }
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))); }
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)); } }