/// <summary> /// 得到IP信息 /// </summary> /// <param name="ip"></param> /// <returns></returns> public virtual IpEntity Get(string ip) { var info = new IpEntity { Ip = ip, Country = "", Province = "", City = "" }; try { if (string.IsNullOrEmpty(ip)) { return(info); } var url = string.Format("{0}{1}", Configuration.ConfigurationManager.GetSetting <string>("SinaIp"), ip); var json = Creator.Get <Winner.Base.IComponent>().GetPageContent(url, "utf-8").DeserializeJson <IDictionary <string, string> >(); if (json != null) { info.Country = json.ContainsKey("country") ? "" : json["country"]; info.Province = json.ContainsKey("province") ? "" : json["province"]; info.City = json.ContainsKey("city") ? "" : json["city"]; } } catch (Exception ex) { Creator.Get <ILog>().AddException(ex); } return(info); }
public static void IncreaseCounter() { try { string ip = IpAddress(); if (IsValidIP(ip)) { HttpCookie cookie = HttpContext.Current.Request.Cookies["Shakaeak_svc"]; if (cookie == null) { IpCountryService ips = new IpCountryService(); IpEntity ipe = ips.GetIpInfo(ip, GetKey()); if (ipe != null) { vc_Create(ipe.CTRY); cookie = new HttpCookie("Shakaeak_svc"); cookie.Expires = DateTime.Now.AddHours(1); HttpContext.Current.Response.Cookies.Add(cookie); } } } } catch { } }
/// <summary> setups the sync logic for member _ip</summary> /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param> private void SetupSyncIp(IEntity2 relatedEntity) { if (_ip != relatedEntity) { DesetupSyncIp(true, true); _ip = (IpEntity)relatedEntity; base.PerformSetupSyncRelatedEntity(_ip, new PropertyChangedEventHandler(OnIpPropertyChanged), "Ip", IpcountryEntity.Relations.IpEntityUsingIpid, true, new string[] { }); } }
/// <summary> Initializes the class members</summary> protected virtual void InitClassMembers() { _ip = null; _state = null; PerformDependencyInjection(); // __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers // __LLBLGENPRO_USER_CODE_REGION_END OnInitClassMembersComplete(); }
public static IpNetworkModel ToModel(this IpEntity entity) { if (entity == null) { return(null); } return(new IpNetworkModel { IpNetwork = entity.IpNetwork }); }
protected IpstateEntity(SerializationInfo info, StreamingContext context) : base(info, context) { if (SerializationHelper.Optimization != SerializationOptimization.Fast) { _ip = (IpEntity)info.GetValue("_ip", typeof(IpEntity)); if (_ip != null) { _ip.AfterSave += new EventHandler(OnEntityAfterSave); } _state = (StateEntity)info.GetValue("_state", typeof(StateEntity)); if (_state != null) { _state.AfterSave += new EventHandler(OnEntityAfterSave); } base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance()); } // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor // __LLBLGENPRO_USER_CODE_REGION_END }
private void saveButton_Click(object sender, EventArgs e) { var se = itemListBox.SelectedIndex; var net = networkComBox.SelectedItem as System.Net.NetworkInformation.NetworkInterface; var model = new IpEntity { Name = nameMaskedTextBox.Text.Trim(), IpAddress = ipMaskedTextBox.Text.Trim(), Id = idMaskedTextBox.Text.Trim(), Gateway = gateMaskedTextBox.Text.Trim(), SubnetMask = subnetMaskedTextBox.Text.Trim(), NetworkName = net?.Name, NetworkID = net?.Id, MACAddress = net?.GetPhysicalAddress()?.ToString(), DNS = dnsMaskedTextBox.Text.Trim() }; var isPass = true; var res = string.Empty; res = IpSwitchHelper.CheckIpEntity(model, ref isPass); if (!isPass) { MessageBox.Show(res, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (model.Id.Equals(tempId) || string.IsNullOrEmpty(model.Id)) { model.Id = Guid.NewGuid().ToString("N"); res = IpSwitchHelper.AddConfig(model); } else { res = IpSwitchHelper.UpdateConfig(model); } LoadConfig(); itemListBox.SelectedIndex = se >= 0 ? se : 0; MessageBox.Show(res, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public static IList <IpEntity> GetIPList(string filename) { var list = new List <IpEntity>(); foreach (var line in File.ReadLines(filename)) { if (string.IsNullOrWhiteSpace(line)) { continue; } var seg = line.Split('|'); var start = seg[0].Split('.'); var end = seg[1].Split('.'); var startB = start.Select(s => byte.Parse(s)).ToArray(); var endB = end.Select(s => byte.Parse(s)).ToArray(); IpEntity info = new IpEntity(); info.Prefix = startB[0]; info.StartIP = seg[0]; info.EndIP = seg[1]; info.Country = seg[2] == "0" ? string.Empty : seg[2]; info.Province = seg[3] == "0" ? string.Empty : seg[3]; info.City = seg[4] == "0" ? string.Empty : seg[4]; info.Isp = seg[5] == "0" ? string.Empty : seg[5]; info.MinIP = IpLocationHelper.IPv4ToInteger(startB); info.MaxIP = IpLocationHelper.IPv4ToInteger(endB); list.Add(info); } return(list); }
public static void DecreaseCounter() { string ip = IpAddress(); if (IsValidIP(ip)) { //HttpCookie cookie = HttpContext.Current.Request.Cookies["Tawfik_svc"]; //if (cookie == null) //{ IpCountryService ips = new IpCountryService(); IpEntity ipe = ips.GetIpInfo(ip, GetKey()); if (ipe != null) { vc_Delete(ipe.CTRY); //cookie = new HttpCookie("Tawfik_svc"); //cookie.Expires = DateTime.Now.AddHours(1); //HttpContext.Current.Response.Cookies.Add(cookie); } //} } }
/// <summary> Removes the sync logic for member _ip</summary> /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param> /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param> private void DesetupSyncIp(bool signalRelatedEntity, bool resetFKFields) { base.PerformDesetupSyncRelatedEntity(_ip, new PropertyChangedEventHandler(OnIpPropertyChanged), "Ip", IpcountryEntity.Relations.IpEntityUsingIpid, true, signalRelatedEntity, "Ipcountry", resetFKFields, new int[] { (int)IpcountryFieldIndex.Ipid }); _ip = null; }