/// <summary> /// Ethernet change event handler /// </summary> /// <param name="ethernet"></param> /// <param name="index"></param> /// <param name="type"></param> protected void OnEthernetInfoChange(EthernetInfo ethernet, ushort index, ushort type) { var handler = EthernetChange; if (handler != null) { var args = new EthernetChangeEventArgs(ethernet, type); args.Index = index; EthernetChange(this, args); } }
/// <summary> /// Constructor overload /// </summary> /// <param name="Ethernet"></param> /// <param name="type"></param> public EthernetChangeEventArgs(EthernetInfo ethernet, ushort type, ushort index) { Adapter = ethernet; Type = type; Index = index; }
/// <summary> /// Constructor overload /// </summary> /// <param name="Ethernet"></param> /// <param name="type"></param> public EthernetChangeEventArgs(EthernetInfo ethernet, ushort type) { Adapter = ethernet; Type = type; }
/// <summary> /// Gets the current ethernet info /// </summary> public void GetEthernetInfo() { OnBoolChange(true, 0, SystemInfoConstants.BusyBoolChange); var adapter = new EthernetInfo(); try { // get lan adapter id var adapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter); // get lan adapter info var dhcpState = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE, adapterId); if (!string.IsNullOrEmpty(dhcpState)) { adapter.DhcpIsOn = (ushort)(dhcpState.ToLower().Contains("on") ? 1 : 0); } adapter.Hostname = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, adapterId); adapter.MacAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS, adapterId); adapter.IpAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, adapterId); adapter.Subnet = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK, adapterId); adapter.Gateway = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER, adapterId); adapter.Domain = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, adapterId); // returns comma seperate list of dns servers with trailing comma // example return: "8.8.8.8 (DHCP),8.8.4.4 (DHCP)," string dns = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DNS_SERVER, adapterId); if (dns.Contains(",")) { string[] dnsList = dns.Split(','); for (var i = 0; i < dnsList.Length; i++) { if (i == 0) { adapter.Dns1 = !string.IsNullOrEmpty(dnsList[0]) ? dnsList[0] : "0.0.0.0"; } if (i == 1) { adapter.Dns2 = !string.IsNullOrEmpty(dnsList[1]) ? dnsList[1] : "0.0.0.0"; } if (i == 2) { adapter.Dns3 = !string.IsNullOrEmpty(dnsList[2]) ? dnsList[2] : "0.0.0.0"; } } } else { adapter.Dns1 = !string.IsNullOrEmpty(dns) ? dns : "0.0.0.0"; adapter.Dns2 = "0.0.0.0"; adapter.Dns3 = "0.0.0.0"; } OnEthernetInfoChange(adapter, 0, SystemInfoConstants.EthernetConfigChange); } catch (Exception e) { var msg = string.Format("GetEthernetInfo failed: {0}", e.Message); CrestronConsole.PrintLine(msg); //ErrorLog.Error(msg); } OnBoolChange(false, 0, SystemInfoConstants.BusyBoolChange); }