示例#1
0
 ///<summary>
 ///构造函数
 ///</summary>
 public ISPScaner()
 {
     buf = new byte[100];
     b3  = new byte[3];
     b4  = new byte[4];
     loc = new IPLocation();
 }
示例#2
0
        [AsyncTimeout(30000)]// 超时时间30秒钟
        public void IndexAsync(long?JournalID)
        {
            IAccessLogService logService = ServiceContainer.Instance.Container.Resolve <IAccessLogService>();

            HttpBrowserCapabilitiesBase bc = HttpContext.Request.Browser;
            AccessLog stat = new AccessLog();

            stat.JournalID       = JournalID == null ? 0 : JournalID.Value;
            stat.Browser         = bc.Browser;
            stat.BrowserType     = bc.Type;
            stat.Version         = bc.Version;
            stat.Platform        = bc.Platform;
            stat.UrlReferrer     = HttpContext.Request.UrlReferrer == null ? "" : HttpContext.Request.UrlReferrer.ToString();
            stat.UserHostAddress = Utils.GetRealIP();
            stat.HttpMethod      = HttpContext.Request.HttpMethod;
            stat.IsAuthenticated = HttpContext.Request.IsAuthenticated;
            stat.LogDateTime     = DateTime.Now.ToLocalTime();

            try
            {
                QQWryLocator ipLocator = new QQWryLocator();
                IPLocation   ipInfo    = ipLocator.Query(stat.UserHostAddress);
                stat.Country = ipInfo.Country;
                stat.City    = ipInfo.Local;
                logService.AddAccessLog(stat);
                //参数要放在这个字典里面实现向Completed action传递
                //AsyncManager.Parameters["ExecResult"] = "<script> var result = 'success';</script>";
            }
            catch (Exception ex)
            {
                LogProvider.Instance.Error("访问日志统计:" + ex.Message);
                //AsyncManager.Parameters["ExecResult"] = "error:" + ex.Message;
            }
            AsyncManager.OutstandingOperations.Decrement();
        }
示例#3
0
        ///<summary>
        ///搜索IP地址搜索
        ///</summary>
        ///<param name="ip"></param>
        private IPLocation SearchIPLocation(string ip)
        {
            using (ipFile = new FileStream(function.VToP("/App_Data/qqwry.dat"), FileMode.Open))
            {
                ipBegin = readLong4(0);
                ipEnd   = readLong4(4);
                //将字符IP转换为字节
                string[] ipSp = ip.Split('.');
                if (ipSp.Length != 4)
                {
                    return(new IPLocation());
                }
                byte[] IP = new byte[4];
                for (int i = 0; i < IP.Length; i++)
                {
                    IP[i] = (byte)(Int32.Parse(ipSp[i]) & 0xFF);
                }

                IPLocation local  = null;
                long       offset = locateIP(IP);

                if (offset != -1)
                {
                    local = getIPLocation(offset);
                }

                if (local == null)
                {
                    local         = new IPLocation();
                    local.Area    = unArea;
                    local.Country = unCountry;
                }
                return(local);
            }
        }
示例#4
0
        private void AddCurrent(UserEntity userEntity)
        {
            Operator       operators = new Operator();
            LoginUserModel loginUser = new LoginUserModel();

            loginUser.UserId        = userEntity.UserId;
            loginUser.Code          = userEntity.EnCode;
            loginUser.Account       = userEntity.Account;
            loginUser.UserName      = userEntity.RealName;
            loginUser.Password      = userEntity.Password;
            loginUser.Secretkey     = userEntity.Secretkey;
            loginUser.CompanyId     = userEntity.OrganizeId;
            loginUser.DepartmentId  = userEntity.DepartmentId;
            loginUser.ManagerId     = userEntity.ManagerId;
            loginUser.Manager       = userEntity.Manager;
            loginUser.HeadIcon      = userEntity.HeadIcon;
            loginUser.IPAddress     = Net.Ip;
            loginUser.IPAddressName = IPLocation.GetLocation(Net.Ip);
            loginUser.ObjectId      = new PermissionBLL().GetObjectStr(userEntity.UserId);
            loginUser.LogTime       = DateTime.Now;
            loginUser.Token         = DESEncrypt.Encrypt(Guid.NewGuid().ToString());
            //判断是否系统管理员
            if (userEntity.Account == "System")
            {
                loginUser.IsSystem = true;
            }
            else
            {
                loginUser.IsSystem = false;
            }
            operators.LoginInfo = loginUser;
            OperatorProvider.Provider.AddCurrent(operators);
        }
示例#5
0
        /// <summary>
        /// 搜索IP地址搜索
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public IPLocation SearchIPLocation(string ip)
        {
            //将字符IP转换为字节
            var ipSp = ip.Split('.');

            if (ipSp.Length != 4)
            {
                ip   = "127.0.0.1";
                ipSp = ip.Split('.');
            }
            var IP = new byte[4];

            for (int i = 0; i < IP.Length; i++)
            {
                IP[i] = (byte)(Int32.Parse(ipSp[i]) & 0xFF);
            }

            IPLocation?local  = null;
            var        offset = LocateIP(IP);

            if (offset != -1)
            {
                local = GetIPLocation(offset);
            }
            if (local is null)
            {
                local = new IPLocation
                {
                    Area = unArea,
                    ISP  = unISP
                };
            }
            return(local);
        }
        public void QueryTest()
        {
            QQWryLocator _qqWry = new QQWryLocator(@"D:\OneDrive\软件\开发\qqwry\qqwry.dat");
            IPLocation   _ip    = _qqWry.Query("116.226.81.32");

            Assert.AreEqual("上海市 电信", string.Format("{0} {1}", _ip.Country, _ip.Local));
        }
示例#7
0
        public void SetAddress(int id = 0)
        {
            string target = Request.QueryString["target"];

            if (string.IsNullOrEmpty(target))
            {
                if (Request.UrlReferrer != null)
                {
                    target = Request.UrlReferrer.ToString();
                }
            }
            M.ShippingAddress address = M.ShippingAddress.GetById(DataSource, id, User.Identity.Id);
            int location;

            if (address == null)
            {
                City city;
                using (IPArea area = new IPArea())
                {
                    IPLocation local = area.Search(ClientIp);
                    using (Country country = Country.GetCountry())
                        city = local.GetCity(country);
                }
                location = city != null ? city.Id : 441900;
            }
            else
            {
                location = address.County;
            }
            this["Target"]   = target;
            this["Location"] = location;
            this["Address"]  = address;
            Render("set_address.html");
        }
示例#8
0
            //构造函数
            #region 构造函数
            /**/
            ///<summary>
            ///构造函数
            ///</summary>
            ///<param name="ipfile">IP数据库文件绝对路径</param>
            #endregion
            private IPWry(string ipfile)
            {
                buf = new byte[100];
                b3  = new byte[3];
                b4  = new byte[4];
                try
                {
                    ipFile = new FileStream(ipfile, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
                catch
                {
                    throw new ArgumentNullException("打开IP数据库文件出错!");
                }

                ipBegin = readLong4(0);
                ipEnd   = readLong4(4);
                loc     = new IPLocation();
            }

            static IPWry _instance;
            static object locker = new object();

            public static IPWry Instance
            {
                get
                {
                    if (_instance == null)
                    {
                        string dataFile = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Assets), "iplib/IPWry.dat");
                        lock (locker)
                        {
                            if (_instance == null)
                            {
                                _instance = new IPWry(dataFile);
                            }
                        }
                    }

                    return(_instance);
                }
            }


            //根据IP地址搜索
            #region 根据IP地址搜索
            /**/
            ///<summary>
            ///搜索IP地址搜索
            ///</summary>
            ///<param name="ip"></param>
            ///<returns></returns>
            #endregion
            public IPLocation SearchIPLocation(string ip)
            {
                //if (ip.Contains(":"))
                //{
                //    ip = IPv6ToIPv4(ip);
                //}

                //将字符IP转换为字节
                string[] ipSp = ip.Split('.');
                if (ipSp.Length != 4)
                {
                    throw new ArgumentOutOfRangeException("不是合法的IP地址!");
                }
                byte[] IP = new byte[4];
                for (int i = 0; i < IP.Length; i++)
                {
                    IP[i] = (byte)(Int32.Parse(ipSp[i]) & 0xFF);
                }

                IPLocation local  = null;
                long       offset = locateIP(IP);

                if (offset != -1)
                {
                    local = getIPLocation(offset);
                }

                if (local == null)
                {
                    local         = new IPLocation();
                    local.area    = unArea;
                    local.country = unCountry;
                }
                return(local);
            }
示例#9
0
        private void button1_Click(object sender, EventArgs e)
        {
            string     ipfilePath = AppDomain.CurrentDomain.BaseDirectory.ToString() + @"QQWry.dat";
            IPLocation loc        = IPReader.GetIPLocation(textBox1.Text.Trim());

            this.textBox2.Text = loc.AreaRegion;
        }
示例#10
0
        public ActionResult SearchTel1314(string telphone, string organizeId)
        {
            //添加查询记录表
            TelphoneReserveSearchEntity searchEntity = new TelphoneReserveSearchEntity()
            {
                IPAddress     = Net.Ip,
                IPAddressName = IPLocation.GetLocation(Net.Ip),
                SearchNumber  = telphone
            };

            searchEntity.Create();
            reserverSearchbll.SaveForm("", searchEntity);


            //是本机构的号码,是本机构的微信昵称
            IEnumerable <TelphonePuEntity> entityList = publl.GetEntityByOrgTel(organizeId, telphone);
            TelphonePuEntity entity = null;

            if (entityList.Count() != 0)
            {
                entity = entityList.First();
            }
            var jsonData = new
            {
                entity = entity,
                state  = 2,//1314广告投放页面状态为2,只看价格
            };

            return(Content(JsonConvert.SerializeObject(jsonData)));
        }
示例#11
0
        public void OperatorAgent(Wechat_AgentEntity agentEntity)
        {
            OperatorAgent operators = new OperatorAgent();

            operators.Id            = agentEntity.Id;
            operators.Pid           = agentEntity.Pid;
            operators.Tid           = agentEntity.Tid;
            operators.OpenId        = agentEntity.OpenId;
            operators.nickname      = agentEntity.nickname;
            operators.Sex           = agentEntity.Sex;
            operators.HeadimgUrl    = agentEntity.HeadimgUrl;
            operators.Province      = agentEntity.Province;
            operators.City          = agentEntity.City;
            operators.Country       = agentEntity.Country;
            operators.LV            = agentEntity.LV;
            operators.profit        = agentEntity.profit;
            operators.Cashout       = agentEntity.Cashout;
            operators.EndDate       = agentEntity.EndDate;
            operators.banner        = agentEntity.banner;
            operators.realname      = agentEntity.realname;
            operators.contact       = agentEntity.contact;
            operators.alipay        = agentEntity.alipay;
            operators.CreateDate    = agentEntity.CreateDate;
            operators.IPAddress     = Net.Ip;
            operators.IPAddressName = IPLocation.GetLocation(Net.Ip);
            operators.LogTime       = DateTime.Now;
            operators.Token         = DESEncrypt.Encrypt(Guid.NewGuid().ToString());
            operators.FuDong        = agentEntity.FuDong;
            operators.OrganizeId    = agentEntity.OrganizeId;
            operators.Category      = agentEntity.Category;
            OperatorAgentProvider.Provider.AddCurrent(operators);
        }
示例#12
0
        public void Index()
        {
            M.MemberInfo member = M.MemberInfo.GetByModify(DataSource, User.Identity.Id);
            DateTime     begin  = (DateTime)Types.GetDefaultValue(TType <DateTime> .Type);

            if (member.Birthday < begin)
            {
                member.Birthday = begin;
            }
            int location = member.County;

            if (location == 0)
            {
                City city;
                using (IPArea area = new IPArea())
                {
                    IPLocation local = area.Search(ClientIp);
                    using (Country country = Country.GetCountry())
                        city = local.GetCity(country);
                }
                location = city != null ? city.Id : 441900;
            }
            this["Location"] = location;
            this["Member"]   = member;
            Render("memberinfo.html");
        }
示例#13
0
        /// <summary>
        /// 普号主页
        /// </summary>
        /// <returns></returns>
        public ActionResult Main(string organizeId, string city)
        {
            //添加靓号浏览实体
            if (!string.IsNullOrEmpty(organizeId))
            {
                var organize = organizebll.GetEntity(organizeId);
                if (!string.IsNullOrEmpty(organize.OrganizeId))
                {
                    ViewBag.FullName   = organize.FullName;
                    ViewBag.Tel        = organize.OuterPhone;
                    ViewBag.Img1       = organize.Img1;
                    ViewBag.Img2       = organize.Img2;
                    ViewBag.Img3       = organize.Img3;
                    ViewBag.Img4       = organize.Img4;
                    ViewBag.city       = city;
                    ViewBag.organizeId = organizeId;
                    ViewBag.InnerPhone = organize.InnerPhone;
                    ViewBag.Nature     = organize.Nature;

                    //添加浏览主页记录
                    //如果不是自己查看,访客才添加查看记录CurrentWxUser.OpenId
                    //UserEntity userEntity = userBLL.CheckLogin(CurrentWxUser.NickName);
                    //if (userEntity == null)
                    if (organize.ManagerId != CurrentWxUser.OpenId)
                    {
                        TelphoneLiangSeeEntity seeEntity = new TelphoneLiangSeeEntity()
                        {
                            OrganizeId    = organizeId,
                            IPAddress     = Net.Ip,
                            IPAddressName = IPLocation.GetLocation(Net.Ip),
                            OpenId        = CurrentWxUser.OpenId,
                            NickName      = CurrentWxUser.NickName,
                            Sex           = CurrentWxUser.Users.Sex,
                            HeadimgUrl    = CurrentWxUser.Users.HeadimgUrl,
                            Province      = CurrentWxUser.Users.Province,
                            City          = CurrentWxUser.Users.City,//微信城市
                            Country       = CurrentWxUser.Users.Country
                        };
                        telphoneliangseebll.SaveForm("", seeEntity);
                    }
                    else
                    {
                        //判断协议是否签写
                        if (organize.AgreementMark != 1)
                        {
                            return(RedirectToAction("Agreement", new { organizeId = organizeId }));
                        }
                    }
                    return(View());
                }
                else
                {
                    return(Content("机构暂时未生效或不存在"));
                }
            }
            else
            {
                return(Content("链接不正确不或完整"));
            }
        }
示例#14
0
        /// <summary>
        /// 按价格随机筛选一个元素
        /// </summary>
        /// <param name="count">数量</param>
        /// <param name="type">广告类型</param>
        /// <param name="cid">分类id</param>
        /// <returns></returns>
        public List <Advertisement> GetsByWeightedPrice(int count, AdvertiseType type, IPLocation ipinfo, int?cid = null)
        {
            var(location, _, _) = ipinfo;
            return(CacheManager.GetOrAdd($"Advertisement:{location.Crc32()}:{type}:{count}-{cid}", _ =>
            {
                var atype = type.ToString("D");
                Expression <Func <Advertisement, bool> > where = a => a.Types.Contains(atype) && a.Status == Status.Available;
                var catCount = CategoryRepository.Count(_ => true);
                where = where.And(a => a.RegionMode == RegionLimitMode.All || (a.RegionMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, a.Regions) : !Regex.IsMatch(location, a.Regions)));
                if (cid.HasValue)
                {
                    var scid = cid.ToString();
                    if (Any(a => a.CategoryIds.Contains(scid)))
                    {
                        where = where.And(a => a.CategoryIds.Contains(scid) || string.IsNullOrEmpty(a.CategoryIds));
                    }
                }

                var list = GetQuery(where).OrderBy(a => - Math.Log(DataContext.Random()) / ((double)a.Price / a.Types.Length * catCount / (string.IsNullOrEmpty(a.CategoryIds) ? catCount : (a.CategoryIds.Length + 1)))).Take(count).ToList();
                var ids = list.Select(a => a.Id).ToArray();
                GetQuery(a => ids.Contains(a.Id)).UpdateFromQuery(a => new Advertisement()
                {
                    DisplayCount = a.DisplayCount + 1
                });

                return list;
            }));
        }
        public void TestMethod5()
        {
            var ip = IPLocation.Parse("北京市海淀区");

            Assert.AreEqual("北京市", ip[0]);
            Assert.AreEqual("海淀区", ip[1]);
        }
示例#16
0
        private static void Main(string[] args)
        {
            try
            {
                QQWryLocator qqWry = new QQWryLocator(@"D:\QQWry.Dat"); //初始化数据库文件,并获得IP记录数,通过Count可以获得

                IPLocation ip = qqWry.Query("222.71.108.200");          //查询一个IP地址
                Console.WriteLine("{0} {1} {2}", ip.IP, ip.Country, ip.Local);

                Stopwatch     stopwatch = new Stopwatch();
                List <string> ips       = new List <string> {
                    "218.5.3.128", "120.67.217.7", "125.78.67.175", "220.250.64.23", "218.5.3.128", "120.67.217.7", "125.78.67.175", "220.250.64.23"
                };
                stopwatch.Start();
                for (int i = 0; i < 100; i++)
                {
                    foreach (string item in ips)
                    {
                        ip = qqWry.Query(item);
                        Console.WriteLine("{0} {1} {2}", ip.IP, ip.Country, ip.Local);
                    }
                }

                stopwatch.Stop();
                Console.WriteLine("查询了800次IP,QQWryLocator 花了{0} ms", stopwatch.ElapsedMilliseconds);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.Read();
        }
示例#17
0
    ///<summary>
    /// 获取指定IP所在地理位置
    ///</summary>
    ///<param name="strIP">要查询的IP地址</param>
    ///<returns></returns>
    public static IPLocation GetIPLocation(string strIP)
    {
        long       ip     = IPToLong(strIP);
        FileStream ipFile = new FileStream(HttpRuntime.AppDomainAppPath + ipfilePath, FileMode.Open, FileAccess.Read);

        long[] ipArray = BlockToArray(ReadIPBlock(ipFile));
        long   offset  = SearchIP(ipArray, 0, ipArray.Length - 1, ip) * 7 + 4;

        ipFile.Position += offset;                   //跳过起始IP
        ipFile.Position  = ReadLongX(3, ipFile) + 4; //跳过结束IP

        IPLocation loc  = new IPLocation();
        int        flag = ipFile.ReadByte(); //读取标志

        if (flag == 1)                       //表示国家和地区被转向
        {
            ipFile.Position = ReadLongX(3, ipFile);
            flag            = ipFile.ReadByte();//再读标志
        }
        long countryOffset = ipFile.Position;

        loc.country = ReadString(flag, ipFile);

        if (flag == 2)
        {
            ipFile.Position = countryOffset + 3;
        }
        flag     = ipFile.ReadByte();
        loc.area = ReadString(flag, ipFile);
        ipFile.Close();
        ipFile = null;
        return(loc);
    }
示例#18
0
        /// <summary>
        /// 根据IP地址获取该IP所在位置信息
        /// </summary>
        /// <param name="ipAddress">IP地址</param>
        /// <returns>IP所在位置</returns>
        /// <remarks>2013-12-16 黄波 创建</remarks>
        /// <remarks>2014-02-07 邵斌 修改:因第三方服务请链接不稳定,进行兼容处理</remarks>
        private IPLocation GetIPLocation(string ipAddress)
        {
            var result = new IPLocation();

            try
            {
                var jsonStr =
                    NetUtil.GetHttpRequest(string.Format("http://ip.taobao.com/service/getIpInfo.php?ip={0}", ipAddress));
                var jsonObject = JObject.Parse(jsonStr);
                if (jsonObject != null && (jsonObject.Property("code") != null && jsonObject["code"].ToString() == "0"))
                {
                    result.Area    = jsonObject["data"]["area"].ToString();
                    result.City    = jsonObject["data"]["city"].ToString();
                    result.Country = jsonObject["data"]["country"].ToString();
                    result.County  = jsonObject["data"]["county"].ToString();
                    ;
                    result.Region = jsonObject["data"]["region"].ToString();
                }
            }
            catch
            {
                //兼容错误 2014-02-07 邵斌 修改
                return(result);
            }
            return(result);
        }
示例#19
0
            public IPLocation getCopy()
            {
                IPLocation ret = new IPLocation();

                ret.country = country;
                ret.area    = area;
                return(ret);
            }
示例#20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ltrlAdminInfo.Text = $"<strong>欢迎<em>{AdminUserName}</em>, 进入{ConfigGlobal.PluginDisplayName} 后台管理</strong>";

            var _ip = IPLocation.GetIP();

            ltrlMyIPInfo.Text = $"<a>IP: {_ip} - {IPLocation.GetIPInfo(_ip)}</a>";
        }
示例#21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ltrlAdminInfo.Text = string.Format("<strong>欢迎<em>{0}</em>, 进入{1} 后台管理</strong>", AdminUserName,
                                               ConfigGlobal_Arsenal.PluginDisplayName);

            var _ip = IPLocation.GetIP();

            ltrlMyIPInfo.Text = string.Format("<a>IP: {0} - {1}</a>", _ip, IPLocation.GetIPInfo(_ip));
        }
示例#22
0
    public static string GetFullLocationName(IPLocation item)
    {
        string LocationString = string.Empty;

        LocationString  = item.city;
        LocationString += (item.region != string.Empty) ? ", " + item.region : string.Empty;
        LocationString += ", " + item.country;

        return(LocationString);
    }
示例#23
0
    public LocationResponse SaveLocation(string SearchText, bool IsID)
    {
        LocationResponse Response = new LocationResponse();

        member = (Member)Session["Member"];

        if (member == null)
        {
            Utility.RememberMeLogin();
        }

        if (member != null)
        {
            if (IsID)
            {
                int        IPLocationID = Int32.Parse(SearchText);
                IPLocation loc          = new IPLocation(IPLocationID);
                member.IPLocationID   = loc.IPLocationID;
                Response.LocationText = loc.city;
                member.Save();
                Response.ResponseType = 1;
            }
            else
            {
                List <IPLocation> IPLocationList = IPLocation.SearchLocation(SearchText);
                Response.LocationList = new List <LocationItem>();

                for (int i = 0; i < IPLocationList.Count; i++)
                {
                    LocationItem locationItem = new LocationItem();
                    locationItem.Lcid = IPLocationList[i].IPLocationID.ToString();
                    locationItem.Text = Server.HtmlEncode(LocationResponse.GetFullLocationName(IPLocationList[i]));
                    Response.LocationList.Add(locationItem);
                }



                if (Response.LocationList.Count == 0)
                {
                    Response.ResponseType = 0;
                }
                else if (Response.LocationList.Count == 1)
                {
                    Response.ResponseType = 1;
                    Response.LocationText = Server.HtmlEncode(IPLocationList[0].city);
                }
                else if (Response.LocationList.Count > 1)
                {
                    Response.ResponseType = 2;
                }
            }
        }

        return(Response);
    }
示例#24
0
        public IPLocation GetIPLocationOfIPAddress(string ipaddress)
        {
            var iplocation = new IPLocation();
            var log        = this.context.Set <ServerLogFile>().Where(l => l.ClientIP.Equals(ipaddress) && !string.IsNullOrEmpty(l.City)).First();

            iplocation.cityName    = log.City;
            iplocation.countryName = log.Country;
            iplocation.longitude   = log.Longitude;
            iplocation.latitude    = log.Latitude;
            return(iplocation);
        }
示例#25
0
        public ActionResult Index()
        {
            TelphoneReserveSeeEntity seeEntity = new TelphoneReserveSeeEntity()
            {
                IPAddress     = Net.Ip,
                IPAddressName = IPLocation.GetLocation(Net.Ip)
            };

            seebll.SaveForm("", seeEntity);
            return(View());
        }
示例#26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ip"></param>
        public static string GetIpCity(string dbPath, string strIp)
        {
            QQWryLocator qqWry = new QQWryLocator(dbPath); //初始化数据库文件,并获得IP记录数,通过Count可以获得
            IPLocation   ip    = qqWry.Query(strIp);       //查询一个IP地址

            return(ip.Country.Trim());

            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();
            //stopwatch.Stop();
            //Console.WriteLine("一共花了{0} ms的时间", stopwatch.ElapsedMilliseconds);
        }
示例#27
0
        public static string GetIpArea(string ip)
        {
            if (string.IsNullOrEmpty(ip))
            {
                return(string.Empty);
            }

            else if (ip == "0.0.0.0")
            {
                return("(未获得IP)");
            }

            else if (ip == "127.0.0.1")
            {
                return("服务器");
            }

            else if (StringUtil.StartsWith(ip, "192.168."))
            {
                return("本地网络");
            }

            else if (StringUtil.StartsWith(ip, "10."))
            {
                return("本地网络");
            }

            else if (ip == "::1")
            {
                return("服务器");
            }

            else if (ip.Contains(":"))
            {
                return("(不支持ipv6)");
            }

            try
            {
                IPLocation location = IPWry.Instance.SearchIPLocation(ip);
                if (location != null)
                {
                    return(location.country + location.area);
                }
            }
            catch
            {
                return("(未知地址)");
            }

            return(string.Empty);
        }
示例#28
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="ipfile">IP数据库文件绝对路径</param>
 /// <returns></returns>
 public QQWry(string ipfile)
 {
     buf = new byte[100];
     b3  = new byte[3];
     b4  = new byte[4];
     lock (this)
     {
         ipFile  = new FileStream(ipfile, FileMode.Open);
         ipBegin = ReadLong4(0);
         ipEnd   = ReadLong4(4);
         loc     = new IPLocation();
     }
 }
示例#29
0
        public void Index()
        {
            City city;

            using (IPArea area = new IPArea())
            {
                IPLocation local = area.Search(ClientIp);
                using (Country country = Country.GetCountry())
                    city = local.GetCity(country);
            }
            this["Location"] = city != null ? city.Id : 441900;
            Render("shippingaddress.html");
        }
示例#30
0
        public ActionResult Register(string mobileCode, string securityCode, string fullName, string password, string verifycode)
        {
            AccountEntity accountEntity = new AccountEntity();

            accountEntity.MobileCode    = mobileCode;
            accountEntity.SecurityCode  = securityCode;
            accountEntity.FullName      = fullName;
            accountEntity.Password      = password;
            accountEntity.IPAddress     = Net.Ip;
            accountEntity.IPAddressName = IPLocation.GetLocation(accountEntity.IPAddress);
            accountEntity.AmountCount   = 30;
            accountBLL.Register(accountEntity);
            return(Success("注册成功。"));
        }
示例#31
0
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(Feed));

        member = (Member)Session["Member"];
        JSNameList = new List<JSName>();


        List<FeedItem> Feed = FeedItem.GetFeed(member.MemberID);

        IEnumerable<FeedItem> SortedFeed = OrderFeed(Feed);

        foreach (var F in SortedFeed)
        {
            FeedHTML += FeedRow(F);
        }

        GenerateProfileVisitorLister(member);

        RSSToken = Server.UrlEncode(RijndaelEncryption.Encrypt(member.Password));

        //MemberProfile memberProfile = member.GetMemberProfileByMemberID();
        //MemberStatus = memberProfile.TagLine.Replace("'", "&#39;");

        MemberStatus = member.MyMemberProfile.TagLine.Replace("'","&#39;");

        if (member.IPLocationID == 0)
        {
            MemberLocation = "not set";
        }
        else
        {
            IPLocation ipLocation = new IPLocation(member.IPLocationID);
            MemberLocation = ipLocation.city;
        }

        GenerateFriendRequestLister();
        GenerateProximityTagsLister();

        JsNameString = JSName.RenderJSArray(JSNameList);
    }
示例#32
0
    public LocationResponse SaveLocation(string SearchText, bool IsID)
    {
        LocationResponse Response = new LocationResponse();

        member = (Member)Session["Member"];

        if (member == null)
        {
            Utility.RememberMeLogin();
        }

        if (member != null)
        {
            if (IsID)
            {
                int IPLocationID = Int32.Parse(SearchText);
                IPLocation loc = new IPLocation(IPLocationID);
                member.IPLocationID = loc.IPLocationID;
                Response.LocationText = loc.city;
                member.Save();
                Response.ResponseType = 1;
            }
            else
            {
                List<IPLocation> IPLocationList = IPLocation.SearchLocation(SearchText);
                Response.LocationList = new List<LocationItem>();

                for (int i = 0; i < IPLocationList.Count; i++)
                {
                    LocationItem locationItem = new LocationItem();
                    locationItem.Lcid = IPLocationList[i].IPLocationID.ToString();
                    locationItem.Text = Server.HtmlEncode(LocationResponse.GetFullLocationName(IPLocationList[i]));
                    Response.LocationList.Add(locationItem);
                }

                

                if (Response.LocationList.Count == 0)
                {
                    Response.ResponseType = 0;
                }
                else if (Response.LocationList.Count == 1)
                {
                    Response.ResponseType = 1;
                    Response.LocationText = Server.HtmlEncode(IPLocationList[0].city);
                }
                else if (Response.LocationList.Count > 1)
                {
                    Response.ResponseType = 2;
                }
            }
        }

        return Response;
    }
示例#33
0
    public static string GetFullLocationName(IPLocation item)
    {
        string LocationString = string.Empty;
        LocationString = item.city;
        LocationString += (item.region!=string.Empty) ? ", "+item.region : string.Empty;
        LocationString += ", "+item.country;

        return LocationString;
    }
示例#34
0
 public IPLocation getCopy()
 {
     IPLocation ret = new IPLocation();
     ret.country = country;
     ret.area = area;
     return ret;
 }
示例#35
0
            //构造函数
            #region 构造函数
            /**/
            ///<summary>
            ///构造函数
            ///</summary>
            ///<param name="ipfile">IP数据库文件绝对路径</param>
            #endregion
            private IPWry(string ipfile)
            {

                buf = new byte[100];
                b3 = new byte[3];
                b4 = new byte[4];
                try
                {
                    ipFile = new FileStream(ipfile, FileMode.Open, FileAccess.Read, FileShare.Read);

                }
                catch
                {
                    throw new ArgumentNullException("打开IP数据库文件出错!");
                }

                ipBegin = readLong4(0);
                ipEnd = readLong4(4);
                loc = new IPLocation();
            }



            static IPWry _instance;
            static object locker = new object();

            public static IPWry Instance
            {
                get
                {
                    if (_instance == null)
                    {
                        string dataFile = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Assets), "iplib/IPWry.dat");
                        lock (locker)
                        {
                            if (_instance == null)
                            {
                                _instance = new IPWry(dataFile);
                            }
                        }
                    }

                    return _instance;
                }
            }


            //根据IP地址搜索
            #region 根据IP地址搜索
            /**/
            ///<summary>
            ///搜索IP地址搜索
            ///</summary>
            ///<param name="ip"></param>
            ///<returns></returns>
            #endregion
            public IPLocation SearchIPLocation(string ip)
            {
                //if (ip.Contains(":"))
                //{
                //    ip = IPv6ToIPv4(ip);
                //}

                //将字符IP转换为字节
                string[] ipSp = ip.Split('.');
                if (ipSp.Length != 4)
                {
                    throw new ArgumentOutOfRangeException("不是合法的IP地址!");
                }
                byte[] IP = new byte[4];
                for (int i = 0; i < IP.Length; i++)
                {
                    IP[i] = (byte)(Int32.Parse(ipSp[i]) & 0xFF);
                }

                IPLocation local = null;
                long offset = locateIP(IP);

                if (offset != -1)
                {
                    local = getIPLocation(offset);
                }

                if (local == null)
                {
                    local = new IPLocation();
                    local.area = unArea;
                    local.country = unCountry;
                }
                return local;
            }
示例#36
0
 /// <summary>
 /// 获取IP信息 根据网络状态来读取
 /// 如果联网 在线读取
 /// 否则 读取本地IP库
 /// </summary>
 /// <returns></returns>
 public static IPLocation GetLocation()
 {
     IPLocation location = new IPLocation();
     string ip = GetClientIP();
     //if (InternetConnectionHelper.Fun_IsNetworkAlive() == InternetConnectionHelper.NetworkStatus.拨号上网
     //    || InternetConnectionHelper.Fun_IsNetworkAlive() == InternetConnectionHelper.NetworkStatus.代理上网)
     //{
     //    location.Address = GetIPAdress(ip);
     //}
     //else
     //{
     IPAddress ipaddr = System.Net.IPAddress.Parse(ip);
     location = GetLocation(ipaddr);
     //}
     return location;
 }