Beispiel #1
2
        public void NewRasEntry()
        {
            ReadOnlyCollection<RasDevice> devices = RasDevice.GetDevices();

            foreach (RasDevice modem in devices)
            {
                if (modem.Name.ToLower().Contains("(pptp)"))
                {
                    this.rDevice = modem;
                }
            }

            newRas = RasEntry.CreateVpnEntry(entryName, entryAddress, RasVpnStrategy.PptpOnly, rDevice, false);

            newRas.Options.RemoteDefaultGateway = false;
            newRas.Options.IPv6RemoteDefaultGateway = false;
            newRas.NetworkProtocols.IPv6 = false;
            newRas.IdleDisconnectSeconds = 10;
            newRas.Options.RequireMSChap2 = true;

            newRas.Options.Internet = false;

            newRas.Options.UseLogOnCredentials = true;

            NetworkCredential cred = new NetworkCredential();
            cred.UserName = this.entryUsername;
            cred.Password = this.entrySecret;

            Data.Pbk.Entries.Add(newRas);
            Data.Pbk.Entries[Data.Pbk.Entries.Last().Name].UpdateCredentials(cred);
        }
Beispiel #2
0
        internal RasConnection(IntPtr handle, RasDevice device, string entryName, string phoneBookPath, Guid entryId, RasConnectionOptions options, Luid sessionId, Guid correlationId, IRasGetConnectStatus statusService, IRasGetConnectionStatistics connectionStatisticsService, IRasHangUp hangUpService, IRasClearConnectionStatistics clearConnectionStatisticsService)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(handle));
            }
            else if (string.IsNullOrWhiteSpace(entryName))
            {
                throw new ArgumentNullException(nameof(entryName));
            }
            else if (string.IsNullOrWhiteSpace(phoneBookPath))
            {
                throw new ArgumentNullException(nameof(phoneBookPath));
            }

            EntryName     = entryName;
            PhoneBookPath = phoneBookPath;
            Handle        = handle;
            Device        = device ?? throw new ArgumentNullException(nameof(device));
            EntryId       = entryId;
            Options       = options ?? throw new ArgumentNullException(nameof(options));
            SessionId     = sessionId;
            CorrelationId = correlationId;

            this.statusService = statusService ?? throw new ArgumentNullException(nameof(statusService));
            this.connectionStatisticsService = connectionStatisticsService ?? throw new ArgumentNullException(nameof(connectionStatisticsService));
            this.hangUpService = hangUpService ?? throw new ArgumentNullException(nameof(hangUpService));
            this.clearConnectionStatisticsService = clearConnectionStatisticsService ?? throw new ArgumentNullException(nameof(clearConnectionStatisticsService));
        }
Beispiel #3
0
        internal RasConnection(IntPtr handle, RasDevice device, string entryName, string phoneBookPath, Guid entryId, RasConnectionOptions options, Luid sessionId, Guid correlationId, IServiceProvider services)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(handle));
            }
            else if (string.IsNullOrWhiteSpace(entryName))
            {
                throw new ArgumentNullException(nameof(entryName));
            }
            else if (string.IsNullOrWhiteSpace(phoneBookPath))
            {
                throw new ArgumentNullException(nameof(phoneBookPath));
            }

            EntryName     = entryName;
            PhoneBookPath = phoneBookPath;
            Handle        = handle;
            Device        = device ?? throw new ArgumentNullException(nameof(device));
            EntryId       = entryId;
            Options       = options ?? throw new ArgumentNullException(nameof(options));
            SessionId     = sessionId;
            CorrelationId = correlationId;
            Services      = services;
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RasConnectionState"/> class.
 /// </summary>
 /// <param name="connectionState">The state of the connection.</param>
 /// <param name="device">The device through which the connection has been established.</param>
 /// <param name="phoneNumber">The phone number dialed for this specific connection.</param>
 /// <param name="localEndpoint">Optional. The local client endpoint information of a virtual private network (VPN) tunnel.</param>
 /// <param name="remoteEndpoint">Optional. The remote client endpoint information of a virtual private network (VPN) tunnel.</param>
 /// <param name="connectionSubState">The state of an Internet Key Exchange version2 (IKEv2) virtual private network (VPN) tunnel.</param>
 public RasConnectionStatus(RasConnectionState connectionState, RasDevice device, string phoneNumber, IPAddress localEndpoint, IPAddress remoteEndpoint, RasConnectionSubState connectionSubState)
 {
     ConnectionState    = connectionState;
     Device             = device ?? throw new ArgumentNullException(nameof(device));
     PhoneNumber        = phoneNumber;
     LocalEndPoint      = localEndpoint;
     RemoteEndPoint     = remoteEndpoint;
     ConnectionSubState = connectionSubState;
 }
Beispiel #5
0
        public static ReadOnlyCollection <RasDevice> GetDevicesByType(RasDeviceType deviceType)
        {
            Collection <RasDevice> tempCollection = new Collection <RasDevice>();

            foreach (RasDevice device in RasDevice.GetDevices())
            {
                if (device.DeviceType == deviceType)
                {
                    tempCollection.Add(device);
                }
            }

            return(new ReadOnlyCollection <RasDevice>(tempCollection));
        }
Beispiel #6
0
        public static RasDevice GetDeviceByName(string name, RasDeviceType deviceType, bool exactMatchOnly)
        {
            if (name == null)
            {
                ThrowHelper.ThrowArgumentNullException("name");
            }

            RasDevice retval = null;

            foreach (RasDevice device in RasDevice.GetDevices())
            {
                if (device.DeviceType == deviceType && ((!exactMatchOnly && device.Name.ToLower(CultureInfo.CurrentCulture).Contains(name.ToLower(CultureInfo.CurrentCulture))) || (exactMatchOnly && string.Compare(name, device.Name, false, CultureInfo.CurrentCulture) == 0)))
                {
                    retval = device;
                    break;
                }
            }

            return(retval);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new broadband entry.
        /// </summary>
        /// <param name="name">The name of the entry.</param>
        /// <param name="device">Required. An <see cref="DotRas.RasDevice"/> to use for connecting.</param>
        /// <param name="useRemoteDefaultGateway"><b>true</b> if the connection should use the remote default gateway, otherwise <b>false</b>.</param>
        /// <returns>A new <see cref="DotRas.RasEntry"/> object.</returns>
        /// <remarks>
        /// <para>
        /// The device for this connection is typically a WAN Miniport (PPPOE) device.
        /// </para>
        /// <para>
        /// <b>Windows XP and later: This method is supported.</b>
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentException"><paramref name="name"/> is an empty string or null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="device"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        public static RasEntry CreateBroadbandEntry(string name, RasDevice device, bool useRemoteDefaultGateway)
        {
            if (string.IsNullOrEmpty(name))
            {
                ThrowHelper.ThrowArgumentException("name", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (device == null)
            {
                ThrowHelper.ThrowArgumentNullException("device");
            }

            RasEntry entry = new RasEntry(name);

            entry.Device = device;
            entry.EncryptionType = RasEncryptionType.Optional;
            entry.EntryType = RasEntryType.Broadband;
            entry.Options.SecureFileAndPrint = true;
            entry.Options.SecureClientForMSNet = true;
            entry.Options.DoNotNegotiateMultilink = true;
            entry.Options.DoNotUseRasCredentials = true;
            entry.Options.Internet = true;
            entry.Options.DisableNbtOverIP = true;
            entry.Options.ModemLights = true;
            entry.Options.SecureLocalFiles = true;
            entry.Options.RequirePap = true;
            entry.Options.PreviewUserPassword = true;
            entry.Options.ShowDialingProgress = true;
            entry.Options.RequireChap = true;
            entry.Options.RequireMSChap2 = true;
            entry.Options.ReconnectIfDropped = true;
            entry.FramingProtocol = RasFramingProtocol.Ppp;
            entry.NetworkProtocols.IP = true;
            entry.PhoneNumber = string.Empty;
            entry.RedialCount = 3;
            entry.RedialPause = 60;

            if (useRemoteDefaultGateway)
            {
                entry.Options.RemoteDefaultGateway = true;

#if (WIN2K8 || WIN7 || WIN8)
                entry.Options.IPv6RemoteDefaultGateway = true;
#endif
            }

#if (WIN2K8 || WIN7 || WIN8)
            entry.NetworkProtocols.IPv6 = true;
#endif

            return entry;
        }
Beispiel #8
0
 /// <summary>
 /// Creates a new broadband entry.
 /// </summary>
 /// <param name="name">The name of the entry.</param>
 /// <param name="device">Required. An <see cref="DotRas.RasDevice"/> to use for connecting.</param>
 /// <returns>A new <see cref="DotRas.RasEntry"/> object.</returns>
 /// <remarks>
 /// <para>
 /// The device for this connection is typically a WAN Miniport (PPPOE) device.
 /// </para>
 /// <para>
 /// <b>Windows XP and later: This method is supported.</b>
 /// </para>
 /// </remarks>
 /// <exception cref="System.ArgumentException"><paramref name="name"/> is an empty string or null reference (<b>Nothing</b> in Visual Basic).</exception>
 /// <exception cref="System.ArgumentNullException"><paramref name="device"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
 public static RasEntry CreateBroadbandEntry(string name, RasDevice device)
 {
     return RasEntry.CreateBroadbandEntry(name, device, true);
 }
Beispiel #9
0
        /// <summary>
        /// Creates a new virtual private network (VPN) entry.
        /// </summary>
        /// <param name="name">The name of the entry.</param>
        /// <param name="serverAddress">The server address to connect to.</param>
        /// <param name="strategy">The virtual private network (VPN) strategy of the connection.</param>
        /// <param name="device">Required. An <see cref="DotRas.RasDevice"/> to use for connecting.</param>
        /// <param name="useRemoteDefaultGateway"><b>true</b> if the connection should use the remote default gateway, otherwise <b>false</b>.</param>
        /// <returns>A new <see cref="DotRas.RasEntry"/> object.</returns>
        /// <remarks>The device for this connection is typically a WAN Miniport (L2TP) or WAN Miniport (PPTP).</remarks>
        /// <exception cref="System.ArgumentException"><paramref name="name"/> or <paramref name="serverAddress"/> is an empty string or null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="device"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        public static RasEntry CreateVpnEntry(string name, string serverAddress, RasVpnStrategy strategy, RasDevice device, bool useRemoteDefaultGateway)
        {
            if (string.IsNullOrEmpty(name))
            {
                ThrowHelper.ThrowArgumentException("name", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (string.IsNullOrEmpty(serverAddress))
            {
                ThrowHelper.ThrowArgumentException("serverAddress", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (device == null)
            {
                ThrowHelper.ThrowArgumentNullException("device");
            }

            RasEntry entry = new RasEntry(name);

            entry.Device = device;
            entry.EncryptionType = RasEncryptionType.Require;
            entry.EntryType = RasEntryType.Vpn;
            entry.FramingProtocol = RasFramingProtocol.Ppp;
            entry.NetworkProtocols.IP = true;
            entry.Options.ModemLights = true;

#if (WIN7 || WIN8)
            if (strategy == RasVpnStrategy.IkeV2First || strategy == RasVpnStrategy.IkeV2Only)
            {
                entry.Options.RequireDataEncryption = true;
                entry.Options.RequireEap = true;
                entry.Options.RequireEncryptedPassword = false;
            }
            else
            {
                entry.Options.RequireEncryptedPassword = true;
            }
#else
            entry.Options.RequireEncryptedPassword = true;
#endif

            entry.Options.PreviewUserPassword = true;
            entry.Options.PreviewDomain = true;
            entry.Options.ShowDialingProgress = true;

            if (useRemoteDefaultGateway)
            {
                entry.Options.RemoteDefaultGateway = true;

#if (WIN2K8 || WIN7 || WIN8)
                entry.Options.IPv6RemoteDefaultGateway = true;
#endif
            }

#if (WINXP || WIN2K8 || WIN7 || WIN8)
            entry.RedialCount = 3;
            entry.RedialPause = 60;

            entry.Options.DoNotNegotiateMultilink = true;
            entry.Options.ReconnectIfDropped = true;
#endif
#if (WIN2K8 || WIN7 || WIN8)
            entry.Options.UseTypicalSettings = true;
            entry.NetworkProtocols.IPv6 = true;
#endif
            entry.PhoneNumber = serverAddress;
            entry.VpnStrategy = strategy;

            return entry;
        }
Beispiel #10
0
 /// <summary>
 /// Creates a new virtual private network (VPN) entry.
 /// </summary>
 /// <param name="name">The name of the entry.</param>
 /// <param name="serverAddress">The server address to connect to.</param>
 /// <param name="strategy">The virtual private network (VPN) strategy of the connection.</param>
 /// <param name="device">Required. An <see cref="DotRas.RasDevice"/> to use for connecting.</param>
 /// <returns>A new <see cref="DotRas.RasEntry"/> object.</returns>
 /// <remarks>The device for this connection is typically a WAN Miniport (L2TP) or WAN Miniport (PPTP).</remarks>
 /// <exception cref="System.ArgumentException"><paramref name="name"/> or <paramref name="serverAddress"/> is an empty string or null reference (<b>Nothing</b> in Visual Basic).</exception>
 /// <exception cref="System.ArgumentNullException"><paramref name="device"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
 public static RasEntry CreateVpnEntry(string name, string serverAddress, RasVpnStrategy strategy, RasDevice device)
 {
     return CreateVpnEntry(name, serverAddress, strategy, device, true);
 }
Beispiel #11
0
        /// <summary>
        /// Creates a new dial-up entry.
        /// </summary>
        /// <param name="name">The name of the entry.</param>
        /// <param name="phoneNumber">The phone number to dial.</param>
        /// <param name="device">Required. An <see cref="DotRas.RasDevice"/> to use for connecting.</param>
        /// <returns>A new <see cref="DotRas.RasEntry"/> object.</returns>
        /// <exception cref="System.ArgumentException"><paramref name="name"/> or <paramref name="phoneNumber"/> is an empty string or null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="device"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        public static RasEntry CreateDialUpEntry(string name, string phoneNumber, RasDevice device)
        {
            if (string.IsNullOrEmpty(name))
            {
                ThrowHelper.ThrowArgumentException("name", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (string.IsNullOrEmpty(phoneNumber))
            {
                ThrowHelper.ThrowArgumentException("phoneNumber", Resources.Argument_StringCannotBeNullOrEmpty);
            }

            if (device == null)
            {
                ThrowHelper.ThrowArgumentNullException("device");
            }

            RasEntry entry = new RasEntry(name);

            entry.Device = device;
            entry.DialMode = RasDialMode.None;
            entry.EntryType = RasEntryType.Phone;
            entry.FramingProtocol = RasFramingProtocol.Ppp;
            entry.IdleDisconnectSeconds = RasIdleDisconnectTimeout.Default;
            entry.NetworkProtocols.IP = true;

#if (WINXP || WIN2K8 || WIN7 || WIN8)
            entry.RedialCount = 3;
            entry.RedialPause = 60;
#endif
#if (WIN2K8 || WIN7 || WIN8)
            entry.NetworkProtocols.IPv6 = true;
#endif

            entry.PhoneNumber = phoneNumber;
            entry.VpnStrategy = RasVpnStrategy.Default;

            return entry;
        }
Beispiel #12
0
 public static RasDevice GetDeviceByName(string name, RasDeviceType deviceType)
 {
     return(RasDevice.GetDeviceByName(name, deviceType, false));
 }