日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

剛剛找到的IP地址對應地區(qū)數(shù)據(jù)庫

系統(tǒng) 2241 0

?? ?項目原因,網(wǎng)上下載了?We7 CMS安裝版,(想下載源碼竟然發(fā)現(xiàn)要加入什么什么源碼小組,還要一年交¥100,暈,這叫什么GP開源?。。。。?,下載下來看了下app_data目錄,驚奇發(fā)現(xiàn)有個ip.db,呵呵,我猜可能是IP地址數(shù)據(jù)庫了,而且是sqlite的,打開一看:

嘿嘿 ,果然是IP地址數(shù)據(jù)庫,而且都轉(zhuǎn)成長IP格式的了,自己寫了個aspx頁面來獲取IP的:
http://5mdn.com/getip.aspx
給網(wǎng)上的人測試發(fā)現(xiàn)其實這個IP數(shù)據(jù)庫也不是很完全的,算了,不管了,先記下來吧,下面是aspx.cs的代碼:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Data;
using System.Data.SQLite;

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string ip = Request.UserHostAddress;
        string longip = IpToLong(ip).ToString();
        litmes.Text = "<h3>您的IP:" + ip + "</h3>";
        litmes.Text += "<h3>轉(zhuǎn)換后的IP:" + longip + "</h3>";
        litmes.Text += "<h4>從IP數(shù)據(jù)庫中取出的記錄:</h4>";

        SQLiteConnection conn = null;
        SQLiteCommand cmd = null;
        SQLiteDataReader sdr = null;

        string connStr = "Data Source=" + HttpContext.Current.Server.MapPath("~/App_Data/ip.db");
        conn = new SQLiteConnection(connStr);
        conn.Open();
        string sql = "SELECT * FROM iptocity where " + longip + " between ip_start and ip_end";
        cmd = new SQLiteCommand(sql, conn);
        DataTable dt = new DataTable();
        using (sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
        {
            dt.Load(sdr);
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

    // 把IP地址轉(zhuǎn)成長數(shù)字,
    // 算法:128.125.1.24 → (128*256*256*256) + (125*256*256) + (1*256) +24
    public static ulong IpToLong(string ip)
    {
        try
        {
            string[] cip = ip.Trim().Split('.');
            string[] aip = new string[4];
            cip.CopyTo(aip, 0);
            if (cip.Length < 3)
            {
                for (int i = 3; i > cip.Length; i--)
                {
                    aip[i] = "0";
                }
            }
            uint[] iip = new uint[4];
            Regex reg = new Regex(@"\d+");
            for (int x = 0; x < aip.Length; x++)
            {
                if (reg.IsMatch(aip[x]))
                    iip[x] = Convert.ToUInt32(aip[x]);
                else
                    iip[x] = 0;
            }
            ulong uip = Convert.ToUInt64(256 * 256 * 256 * iip[0] + 256 * 256 * iip[1] + 256 * iip[2] + iip[3]);
            return uip;
        }
        catch (Exception ess)
        {
            throw ess;
        }
    }

}

  
? 相關(guān)文件下載: 點擊下載

剛剛找到的IP地址對應地區(qū)數(shù)據(jù)庫


更多文章、技術(shù)交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 阿荣旗| 高雄市| 陆河县| 措美县| 芜湖县| 黔江区| 海城市| 寿光市| 留坝县| 车致| 麻城市| 宜都市| 太康县| 固镇县| 武清区| 遵义市| 湘乡市| 大悟县| 红桥区| 株洲市| 崇仁县| 油尖旺区| 建德市| 沧州市| 新津县| 苍南县| 大新县| 南安市| 岗巴县| 衢州市| 凤庆县| 高清| 泽州县| 韶山市| 仁化县| 灵山县| 子洲县| 屏东市| 通州区| 墨玉县| 城市|