求一个将Access的IP1(10位),IP2(10位)格式的IP数据库转为192.168.0.1格式的函数(C#描述的)。谢谢!
以及最新的IP数据库
[email protected]
谢谢!!!

解决方案 »

  1.   

    即是说数据库中有:IP1             IP2            国家     地区
                     1234567890     1234567890        XX       XX
    这样的字段,如何用一个函数将IP1,IP2两个字段转换为192.168.0.1格式的。
      

  2.   

    IP地址库动网论坛数据库里就有如果IP1,IP2没有一定的规则,恐怕很难分解,因为IP地址分段数值取值范围太大,逐一分解比较困难
      

  3.   

    string Address(string IP)
    {
    string ip1,ip2,ip3,ip4;
    long num;
    if(IP=="127.0.0.1")
    IP="192.168.0.1";
    if(IP.Substring(0,8)=="192.168.")
    {
    Address="内部局域网";
    return;
    }
    int index=IP.IndexOf(".");     //将IP分开4个段。
    int index2=IP.IndexOf(".",index);
    int index3=IP.IndexOf(".",index2);
    IP1=IP.Substring(0,index);
    IP2=IP.Substring(index,index2-index);
    IP3=IP.Substring(index2,index3-index2);
    IP4=IP.Substring(index3);
    num=Convert.ToInt32(IP1)*256*256*256+Convert.ToInt32(IP2)*256*256*256+Convert.ToInt32(IP3)*256*256*256+Convert.ToInt32(IP4)*256*256*256;//得到一个10位数
    OleDbConnection conn=new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Server.MapPath(ConfigurationSettings.AppSettings["数据库"]));
    OleDbCommand comd=new OleDbCommand("Select Top 1 country,city From XX Where ip1 <=" + num.ToString() + " and ip2 >=" + num.ToString(), conn);//判断在两个IP1,IP2字段间的就是该IP,从而得到国家,地区等到信息。

    dr.Close();
    comd.Connection.Close();
    conn.Dispose();各位高手看看这样有问题吗??不知道大家写论坛时显示对方IP时是如何做的???大家跟贴吧?学习学习!!!
      

  4.   

    C# 
    //
    // 将基于字符串的IP转换成主机字节序的IP地址
    //
    private static System.UInt32 ParseIPAddress(string strIPAddress)
    {
    IPAddress ipAddr=IPAddress.Parse(strIPAddress);
    byte[] ipBytes=ipAddr.GetAddressBytes();
    return (UInt32)((ipBytes[0]<<24)+(ipBytes[1]<<16)+(ipBytes[2]<<8)+(ipBytes[3]));
    }
    SQL:
    alter function fIP2Int(@ip varchar(20))
    returns bigint
    as 
    begin
    --切出四个IP段
    declare @ip1 int,@ip2 int,@ip3 int,@ip4 intselect @ip1 = convert(int,substring(@ip,1,charindex('.',@ip)-1))
    select @ip = right(@ip,len(@ip)-charindex('.',@ip))
    select @ip2 = convert(int,substring(@ip,1,charindex('.',@ip)-1))
    select @ip = right(@ip,len(@ip)-charindex('.',@ip))
    select @ip3 = convert(int,substring(@ip,1,charindex('.',@ip)-1))
    select @ip = right(@ip,len(@ip)-charindex('.',@ip))
    select @ip4 = @ip-- 返回10位数字return 
    convert(bigint,@ip1)*256*256*256 +
    convert(bigint,@ip2)*256*256 +
    convert(bigint,@ip3)*256 +
    convert(bigint,@ip4)
    end
    --------------------------
    觉得好要给分
      

  5.   

    关于IP库
    现在我能得到的IP库太详细了,有些竟然有大学的第几楼第几室,或‘ADSL’用户
    我需要的只是
    ip1 ip2 国家 省市地区(一般是城市)要将那个ip 库进行合并呀,痛苦,
    有哪位高人有这种IP数据库
      

  6.   

    ghibrain(雨子杉):
       你的程序是基于ip1 ip2 国家 省市地区(一般是城市)这种形式的吧???是不是???
     是一个储存过程吗?如何用,我还不会用储存过程啊??刚学不久。
      

  7.   

    ghibrain(雨子杉)
    兄弟,说说啊。