Example #1
0
        private bool ManageClientReservation(List <NetworkInterface> clientNetworks, List <IPAddress> clientAddresses, SecurityActivityData activityData, bool deleteReservation = false)
        {
            try
            {
                IPAddress primaryAddress   = clientAddresses.FirstOrDefault(x => x.IsInSameSubnet(IPAddress.Parse(activityData.PrimaryDhcpServerIPAddress)));
                IPAddress secondaryAddress = clientAddresses.FirstOrDefault(x => x.IsInSameSubnet(IPAddress.Parse(activityData.SecondaryDhcpServerIPAddress)));

                clientNetworks.ForEach(x => TraceFactory.Logger.Info("network" + x.Name));
                clientAddresses.ForEach(x => TraceFactory.Logger.Info("Address" + x.ToString()));

                string primaryNetworkName   = CtcUtility.GetClientNetworkName(clientAddresses.FirstOrDefault(x => x.Equals(primaryAddress)).ToString());
                string secondaryNetworkName = CtcUtility.GetClientNetworkName(clientAddresses.FirstOrDefault(x => x.Equals(secondaryAddress)).ToString());

                if (deleteReservation)
                {
                    DeleteReservation(primaryAddress.ToString(), activityData.PrimaryDhcpServerIPAddress, clientNetworks.FirstOrDefault(x => x.Name.EqualsIgnoreCase(primaryNetworkName)).GetPhysicalAddress().ToString());
                    DeleteReservation(secondaryAddress.ToString(), activityData.SecondaryDhcpServerIPAddress, clientNetworks.FirstOrDefault(x => x.Name.EqualsIgnoreCase(secondaryNetworkName)).GetPhysicalAddress().ToString());
                }
                else
                {
                    DeleteReservation(primaryAddress.ToString(), activityData.PrimaryDhcpServerIPAddress, clientNetworks.FirstOrDefault(x => x.Name.EqualsIgnoreCase(primaryNetworkName)).GetPhysicalAddress().ToString());
                    DeleteReservation(secondaryAddress.ToString(), activityData.SecondaryDhcpServerIPAddress, clientNetworks.FirstOrDefault(x => x.Name.EqualsIgnoreCase(secondaryNetworkName)).GetPhysicalAddress().ToString());
                    CreateReservation(primaryAddress.ToString(), activityData.PrimaryDhcpServerIPAddress, clientNetworks.FirstOrDefault(x => x.Name.EqualsIgnoreCase(primaryNetworkName)).GetPhysicalAddress().ToString());
                    CreateReservation(secondaryAddress.ToString(), activityData.SecondaryDhcpServerIPAddress, clientNetworks.FirstOrDefault(x => x.Name.EqualsIgnoreCase(secondaryNetworkName)).GetPhysicalAddress().ToString());
                }

                return(true);
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Debug(ex.Message);
                return(false);
            }
        }
Example #2
0
 /// <summary>
 /// Returns the client network name provided by a particular server.
 /// </summary>
 /// <param name="serverIpAddress">IP Address of the server</param>
 /// <returns>IPAddress of local machine</returns>
 public string GetClientNetworkName(string serverIPAddress)
 {
     return(CtcUtility.GetClientNetworkName(serverIPAddress));
 }