private void LoadIPWhiteList() { try { XElement xml = XElement.Load(Global.IsolateResPath("Config/IPWhiteList.xml")); if (null != xml) { List <IPWhiteList> NewIPWhiteList = new List <IPWhiteList>(); IEnumerable <XElement> xmlItems = xml.Elements(); foreach (XElement xmlItem in xmlItems) { IPWhiteList value = new IPWhiteList(); value.ID = (int)Global.GetSafeAttributeLong(xmlItem, "ID"); IPAddress MinIP = IPAddress.Parse(Global.GetSafeAttributeStr(xmlItem, "MinIP")); byte[] byteMinIP = MinIP.GetAddressBytes(); value.MinIP = (uint)((int)byteMinIP[0] << 24 | (int)byteMinIP[1] << 16 | (int)byteMinIP[2] << 8 | (int)byteMinIP[3]); IPAddress MaxIP = IPAddress.Parse(Global.GetSafeAttributeStr(xmlItem, "MaxIP")); byte[] byteMaxIP = MaxIP.GetAddressBytes(); value.MaxIP = (uint)((int)byteMaxIP[0] << 24 | (int)byteMaxIP[1] << 16 | (int)byteMaxIP[2] << 8 | (int)byteMaxIP[3]); NewIPWhiteList.Add(value); } this._IPWhiteList = NewIPWhiteList; } } catch (Exception ex) { LogManager.WriteException(ex.ToString() + "xmlFileName=IPWhiteList.xml"); } }
/// <summary> /// 加载IP白名单 /// </summary> void LoadIPWhiteList() { try { XElement xml = XElement.Load(Global.IsolateResPath(IPWhiteListfileName)); if (null == xml) { return; } List <IPWhiteList> NewIPWhiteList = new List <IPWhiteList>(); IEnumerable <XElement> xmlItems = xml.Elements(); foreach (var xmlItem in xmlItems) { IPWhiteList value = new IPWhiteList(); value.ID = (int)Global.GetSafeAttributeLong(xmlItem, "ID"); IPAddress MinIP = IPAddress.Parse(Global.GetSafeAttributeStr(xmlItem, "MinIP")); byte[] byteMinIP = MinIP.GetAddressBytes(); value.MinIP = (uint)(byteMinIP[0] << 24) | (uint)(byteMinIP[1] << 16) | (uint)(byteMinIP[2] << 8) | (uint)(byteMinIP[3]); IPAddress MaxIP = IPAddress.Parse(Global.GetSafeAttributeStr(xmlItem, "MaxIP")); byte[] byteMaxIP = MaxIP.GetAddressBytes(); value.MaxIP = (uint)(byteMaxIP[0] << 24) | (uint)(byteMaxIP[1] << 16) | (uint)(byteMaxIP[2] << 8) | (uint)(byteMaxIP[3]); NewIPWhiteList.Add(value); } _IPWhiteList = NewIPWhiteList; } catch (System.Exception ex) { LogManager.WriteException(ex.ToString() + "xmlFileName=" + "IPWhiteList.xml"); } }