private static bool SetNetworkIpInfo(ControlSystemConfig.NetworkProperties config) { bool reboot = false; if (config != null) { //Check to see if IP address needs to be updated if (String.Compare(config.staticIpAddress, CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_IPADDRESS, config.adapterId)) != 0) { reboot = CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_STATIC_IPADDRESS, config.adapterId, config.staticIpAddress); } //Check to see if Net mask address needs to be updated if (String.Compare(config.staticNetMask, CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_IPMASK, config.adapterId)) != 0) { reboot = CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_STATIC_IPMASK, config.adapterId, config.staticNetMask); } //Check to see if Def router needs to be updated if (String.Compare(config.staticNetMask, CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_STATIC_ROUTER, config.adapterId), true) != 0) { reboot = CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_STATIC_DEFROUTER, config.adapterId, config.staticDefRouter); } } return(reboot); }
private static bool SetNetworkDnsServers(ControlSystemConfig.NetworkProperties config) { if (config != null & config.dnsServers != null) { //Get the local DNS servers string[] localDnsServers = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DNS_SERVER, config.adapterId).Split(','); if (localDnsServers.Length != config.dnsServers.Length) { //There's definetly a change - we'll simply override the servers DNS recods OverrideDnsServers(config, localDnsServers); return(true); } else { for (int i = 0; i < localDnsServers.Length; i++) { //If any of the records is differnet, simply override all and return true if (String.Compare(localDnsServers[i], config.dnsServers[i], true) != 0) { OverrideDnsServers(config, localDnsServers); return(true); } } } } return(false); }
private static bool SetNetworkDomainName(ControlSystemConfig.NetworkProperties config) { if (config != null) { if (String.Compare(config.domainName, CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, config.adapterId), true) != 0) { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_DOMAINNAME, config.adapterId, config.hostName)); } } return(false); }
private static void OverrideDnsServers(ControlSystemConfig.NetworkProperties config, string[] oldServers) { //Remove current servers foreach (string ds in oldServers) { CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.REMOVE_DNS_SERVER, config.adapterId, ds); } //Add new servers foreach (string ds in config.dnsServers) { CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.ADD_DNS_SERVER, config.adapterId, ds); } }
private static bool SetNetworkWebServer(ControlSystemConfig.NetworkProperties config) { if (config != null & config.webServer != null) { //Webserver is off, but should be set to on if ((bool)config.webServer & CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_WEBSERVER_STATUS, config.adapterId) == "OFF") { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_WEBSERVER_STATE, config.adapterId, "ON")); } //Webserver is on, but should be set to off if (!(bool)config.webServer & CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_WEBSERVER_STATUS, config.adapterId) == "ON") { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_WEBSERVER_STATE, config.adapterId, "OFF")); } } return(false); //We didn't change anything }
private static bool SetNetworkDhcp(ControlSystemConfig.NetworkProperties config) { if (config != null) { //DHCP is currently off, but should be set to on if (config.dhcp & CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, config.adapterId) == "OFF") { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_DHCP_STATE, config.adapterId, "ON")); } //DHCP is currently on, but should be set to off if (!config.dhcp & CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, config.adapterId) == "ON") { return(CrestronEthernetHelper.SetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_SET.SET_DHCP_STATE, config.adapterId, "ON")); } } return(false); //We didn't change anything }
/// <summary> /// Appling network configurations /// </summary> /// <param name="config"></param> /// <returns>True if a reboot is required. False othersie.</returns> public static bool ApplyControlSystemNetworkConfig(ControlSystemConfig.NetworkProperties config) { bool reboot = false; //DHCP reboot = reboot | SetNetworkDhcp(config); //Webserver reboot = reboot | SetNetworkWebServer(config); //Static IP Address reboot = reboot | SetNetworkIpInfo(config); //Hostname reboot = reboot | SetNetworkHostName(config); //Domain Name reboot = reboot | SetNetworkDomainName(config); //DNS Servers reboot = reboot | SetNetworkDnsServers(config); return(reboot); }