Exemplo n.º 1
0
 /// <summary>
 /// Creates a DHCP pool and fills it according to the given params
 /// </summary>
 /// <param name="ipaPoolStart">The start IP address of the pool</param>
 /// <param name="ipaPoolEnd">The end IP address of the pool</param>
 /// <param name="ipaStandardgateway">The standardgateway's IP address</param>
 /// <param name="ipaDNSServer">The DNS server's IP address</param>
 /// <param name="smMask">The subnetmask</param>
 public DHCPPool(IPAddress ipaPoolStart, IPAddress ipaPoolEnd, IPAddress ipaStandardgateway, IPAddress ipaDNSServer, Subnetmask smMask) : this()
 {
     IPAddress[] ipRange = IPAddressAnalysis.GetIPRange(ipaPoolStart, ipaPoolEnd);
     foreach (IPAddress ipa in ipRange)
     {
         lDHCPPool.Add(new DHCPPoolItem(ipa, smMask, ipaStandardgateway, ipaDNSServer));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Adds the given NAT address range to the external range
 /// </summary>
 /// <param name="toAdd"></param>
 public void AddToExternalRange(NATAddressRange toAdd)
 {
     lock (lExternalRange)
     {
         lExternalAddressPool.AddRange(IPAddressAnalysis.GetIPRange(
                                           IPAddressAnalysis.GetClasslessNetworkAddress(toAdd.NetworkAddress, toAdd.Subnetmask),
                                           IPAddressAnalysis.GetClasslessBroadcastAddress(toAdd.NetworkAddress, toAdd.Subnetmask))
                                       );
         lExternalRange.Add(toAdd);
     }
     InvokePropertyChanged();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Removes the given NAT address range from the external range. Open connections will not be interrupted.
 /// </summary>
 /// <param name="toRemove">The address range to remove</param>
 public void RemoveFromExternalRange(NATAddressRange toRemove)
 {
     lock (lExternalRange)
     {
         foreach (IPAddress ipa in IPAddressAnalysis.GetIPRange(
                      IPAddressAnalysis.GetClasslessNetworkAddress(toRemove.NetworkAddress, toRemove.Subnetmask),
                      IPAddressAnalysis.GetClasslessBroadcastAddress(toRemove.NetworkAddress, toRemove.Subnetmask))
                  )
         {
             lExternalAddressPool.Remove(ipa);
         }
         lExternalRange.Remove(toRemove);
     }
     InvokePropertyChanged();
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a pool from the given parameters
        /// </summary>
        /// <param name="ipaStart">The start address of the pool range</param>
        /// <param name="ipaEnd">The end address of the pool range</param>
        /// <param name="ipi">The IP idnterface to which this pool should be associated</param>
        /// <param name="iAddrCounter">The index of the address of the interface to use if the interface has multiple IP addresses assigned</param>
        protected virtual void CreatePool(IPAddress ipaStart, IPAddress ipaEnd, IPInterface ipi, int iAddrCounter)
        {
            if (ipaStart.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork || ipaEnd.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork)
            {
                throw new ArgumentException("Only IPv4 is supported at the moment");
            }

            DHCPPool dhPool = GetPoolForInterface(ipi);

            IPAddress[] ipRange = IPAddressAnalysis.GetIPRange(ipaStart, ipaEnd);

            foreach (IPAddress ipa in ipRange)
            {
                IPInterface ipiInterface = ipi;
                IPAddress   ipAddress    = ipa;
                IPAddress   ipGateway;
                Subnetmask  smMask      = ipi.Subnetmasks[iAddrCounter];
                IPAddress   ipDnsServer = IPAddress.Any;


                if (ipaGateway == null)
                {
                    ipGateway = ipi.IpAddresses[iAddrCounter];
                }
                else
                {
                    ipGateway = ipaGateway;
                }
                if (ipaDNSServer == null)
                {
                    ipDnsServer = ipi.IpAddresses[iAddrCounter];
                }
                else
                {
                    ipDnsServer = ipaDNSServer;
                }

                if (dhPool.GetItemForAddress(ipAddress) == null)
                {
                    DHCPPoolItem dhPoolItem = new DHCPPoolItem(ipAddress, smMask, ipGateway, ipDnsServer);
                    AddPoolItem(dhPoolItem, dhPool, ipi);
                }
            }
        }