Exemple #1
0
        public static AdaptorNetworkInfo GetAdaptorNetworkInfo(string nameOrDesc)
        {
            Logger.Info("GetAdaptorNetworkInfo for " + nameOrDesc);
            var physicalNics = GetAllActiveLocalPhysicalNics();

            foreach (var networkInterface in physicalNics)
            {
                if (networkInterface.Description.Equals(nameOrDesc) || networkInterface.Name.Equals(nameOrDesc))
                {
                    var adaptorDescriptionOrName = networkInterface.Description;
                    var adaptorNetworkInfo       = new AdaptorNetworkInfo
                    {
                        Description   = adaptorDescriptionOrName,
                        IpAddress     = GetAdapterIp4Address(adaptorDescriptionOrName),
                        Gateway       = NetworkManagement.GetGatewayForAdaptor(adaptorDescriptionOrName),
                        IsDhcpEnabled = !NetworkManagement.IsNetworkedWithStaticIp(adaptorDescriptionOrName),
                        Name          = networkInterface.Name
                    };
                    Logger.Info("GetAdaptorNetworkInfo Found Match " + adaptorNetworkInfo);
                    return(adaptorNetworkInfo);
                }
            }

            return(new AdaptorNetworkInfo());
        }
Exemple #2
0
        public static void RestorePrevNetworkInfo(AdaptorNetworkInfo prevAdaptorNetworkInfo)
        {
            if (prevAdaptorNetworkInfo == null)
            {
                return;
            }

            Logger.Info("Restoring Previos Network Information" + prevAdaptorNetworkInfo);
            try
            {
                if (prevAdaptorNetworkInfo.IsDhcpEnabled)
                {
                    NetworkManagement.SetDhcp(prevAdaptorNetworkInfo.Name);
                }
                else
                {
                    NetworkManagement.SetSystemIp(prevAdaptorNetworkInfo.IpAddress.ToString(), "255.255.255.0", prevAdaptorNetworkInfo.Description);
                }
            }
            catch (Exception e)
            {
                Logger.Info(e.Message + (e.InnerException?.Message ?? ""));
            }
        }