刚刚找到的IP地址对应地区数据库

简介: 项目原因,网上下载了 We7 CMS安装版,(想下载源码竟然发现要加入什么什么源码小组,还要一年交¥100,晕,这叫什么GP开源啊!!!),下载下来看了下app_data目录,惊奇发现有个ip.db,呵呵,我猜可能是IP地址数据库了,而且是sqlite的,打开一看:嘿嘿 ,果然是IP地址数据库,而且都转成长IP格式的了,自己写了个aspx页面来获取IP的:http://5mdn.
   项目原因,网上下载了 We7 CMS安装版,(想下载源码竟然发现要加入什么什么源码小组,还要一年交¥100,晕,这叫什么GP开源啊!!!),下载下来看了下app_data目录,惊奇发现有个ip.db,呵呵,我猜可能是IP地址数据库了,而且是sqlite的,打开一看:

嘿嘿 ,果然是IP地址数据库,而且都转成长IP格式的了,自己写了个aspx页面来获取IP的:
http://5mdn.com/getip.aspx

给网上的人测试发现其实这个IP数据库也不是很完全的,算了,不管了,先记下来吧,下面是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>转换后的IP: "   +  longip  +   " </h3> " ;
        litmes.Text 
+=   " <h4>从IP数据库中取出的记录:</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地址转成长数字,
    
//  算法: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;
        }
    }

}

 

相关文件下载:点击下载


目录
相关文章
|
11月前
|
网络协议 关系型数据库 MySQL
如何搭建MariaDB并实现无公网ip环境远程连接本地数据库
如何搭建MariaDB并实现无公网ip环境远程连接本地数据库
174 0
|
13天前
|
监控 数据库
【YashanDB 知识库】ycm 托管数据库时报错 OM host ip:127.0.0.1 is not support join to YCM
在托管数据库时,若 OM 的 IP 被设置为 127.0.0.1,将导致无法托管至 YCM,并使数据库失去监控。此问题源于安装时修改了 OM 的监听 IP。解决方法包括:将 OM 的 IP 修改为本机实际 IP 或 0.0.0.0,同时更新 env 文件及 yasom 后台数据库中的相关配置。经验总结指出,应避免非必要的后台 IP 修改,且数据库安装需遵循规范,不使用仅限本机访问的 IP(如 127.0.0.1)。
|
1月前
|
监控 数据库
【YashanDB知识库】ycm托管数据库时报错OM host ip:127.0.0.1 is not support join to YCM
在托管数据库时,若OM的IP被设置为127.0.0.1,则不支持托管到YCM,导致数据库无法正常监控。此问题源于安装时修改了OM监听IP为127.0.0.1。解决方法为将OM的IP修改为本机实际IP或0.0.0.0,并更新yasom后台数据库中的相关配置。建议遵循规范安装,避免使用仅限本机访问的IP(如127.0.0.1),以减少潜在风险。
|
1月前
|
监控 数据库
ycm托管数据库时报错OM host ip:127.0.0.1 is not support join to YCM-YashanDB
ycm托管数据库时报错OM host ip:127.0.0.1 is not support join to YCM-YashanDB
|
6月前
|
运维 监控 安全
【YashanDB知识库】ycm托管数据库时报错OM host ip:127.0.0.1 is not support join to YCM
总之,解决“OM host ip: 127.0.0.1 is not supported to join to YCM”的关键在于理解集群管理对IP地址的使用要求,并据此做出相应的配置调整,确保集群的稳定性和数据一致性。
52 1
|
9月前
|
前端开发 NoSQL 数据库
部署常用的流程,可以用后端,连接宝塔,将IP地址修改好,本地只要连接好了,在本地上前后端跑起来,前端能够跑起来,改好了config.js资料,后端修改好数据库和连接redis,本地上跑成功了,再改
部署常用的流程,可以用后端,连接宝塔,将IP地址修改好,本地只要连接好了,在本地上前后端跑起来,前端能够跑起来,改好了config.js资料,后端修改好数据库和连接redis,本地上跑成功了,再改
|
数据库
云效构建需要链接数据库 数据库有ip白名单 在哪里看构建集群的ip?
云效构建需要链接数据库 数据库有ip白名单 在哪里看构建集群的ip?
109 1
|
9月前
|
数据库
数据库bug-[08001] Could not create connection to database server. Attempted reconnect 3,主机名ip必须写对
数据库bug-[08001] Could not create connection to database server. Attempted reconnect 3,主机名ip必须写对
|
10月前
|
关系型数据库 数据库 RDS
阿里云数据库加ip白名单
阿里云数据库加ip白名单
393 0
|
11月前
|
关系型数据库 MySQL 数据库
mysql数据库指定ip远程访问
mysql数据库指定ip远程访问
293 0

热门文章

最新文章

下一篇
oss创建bucket