国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ASP.NET根據IP獲取省市地址

2019-11-17 01:49:41
字體:
來源:轉載
供稿:網友

asp.net根據ip獲取省市地址

1、在網站的跟路徑下面添加 QQWry.dat 文件,這個文件是IP數據庫文件

2、添加以下一個類 IPScanner

C# 代碼 復制
 public class IPScanner    {        //私有成員#region 私有成員         PRivate string dataPath;        private string ip;        private string country;        private string local;        private long firstStartIp = 0;        private long lastStartIp = 0;        private FileStream objfs = null;        private long startIp = 0;        private long endIp = 0;        private int countryFlag = 0;        private long endIpOff = 0;        private string errMsg = null;        //構造函數#region 構造函數         public IPScanner()        {            this.dataPath = System.Web.HttpContext.Current.Server.MapPath("/ipdata/QQWry.dat");        }        //公共屬性#region 公共屬性         public string DataPath        {            set { dataPath = value; }        }        public string IP        {            set { ip = value; }        }        public string Country        {            get { return country; }        }        public string Local        {            get { return local; }        }        public string ErrMsg        {            get { return errMsg; }        }        //搜索匹配數據#region 搜索匹配數據         private int QQwry()        {            string pattern = @"(((//d{1,2})|(1//d{2})|(2[0-4]//d)|(25[0-5]))//.){3}((//d{1,2})|(1//d{2})|(2[0-4]//d)|(25[0-5]))";            Regex objRe = new Regex(pattern);            Match objMa = objRe.Match(ip);            if (!objMa.Success)            {                this.errMsg = "IP格式錯誤";                return 4;            }            long ip_Int = this.IpToInt(ip);            int nRet = 0;            if (ip_Int >= IpToInt("127.0.0.0") && ip_Int <= IpToInt("127.255.255.255"))            {                this.country = "本機內部環回地址";                this.local = "";                nRet = 1;            }            else if ((ip_Int >= IpToInt("0.0.0.0") && ip_Int <= IpToInt("2.255.255.255")) || (ip_Int >= IpToInt("64.0.0.0") && ip_Int <= IpToInt("126.255.255.255")) || (ip_Int >= IpToInt("58.0.0.0") && ip_Int <= IpToInt("60.255.255.255")))
上一篇:性能優化系列

下一篇:函數調用、枚舉

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 莱芜市| 蕉岭县| 昭觉县| 开远市| 浑源县| 德钦县| 始兴县| 杭锦后旗| 本溪市| 诏安县| 淮北市| 宜州市| 原阳县| 武平县| 开阳县| 仁寿县| 甘孜县| 宜章县| 罗定市| 潍坊市| 松阳县| 林州市| 昌吉市| 昭平县| 二连浩特市| 博白县| 垣曲县| 孙吴县| 西畴县| 博兴县| 赣州市| 汉中市| 青浦区| 南京市| 万盛区| 渑池县| 石河子市| 龙泉市| 南康市| 拜泉县| 喀喇沁旗|