c# 导出纯真ip库到sqlserver 本帖最后由 ranmer 于 2009-11-06 15:15:58 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //区间头Search_Set = IndexInfoAtPos(Search_Index_Set);//区间尾Search_End = IndexInfoAtPos(Search_Index_End);看看这两个值 纯真ip库 它没有存储IP地址字符串,也不是一条条“IP、国家、地区” 这样的信息。它IP是用UInt32 来表示的。你要把这个UInt32表示的IP,转成"0.0.0.0"形式。其中IndexInfoAtPos(i).Offset就是这个UInt32吧。。没有仔细研究过这个库 根据网上的介绍,他的排列是[ip][国家][地区][ip]是7个字节 4节点是起始ip 3个节点是结束ip(也叫上限)他的ip址址转成uint的代码如下 public UInt32 IPToUInt32(string IpValue) { string[] IpByte = IpValue.Split('.'); Int32 nUpperBound = IpByte.GetUpperBound(0); if (nUpperBound != 3) { IpByte = new string[4]; for (Int32 i = 1; i <= 3 - nUpperBound; i++) IpByte[nUpperBound + i] = "0"; } byte[] TempByte4 = new byte[4]; for (Int32 i = 0; i <= 3; i++) { //'如果是.Net 2.0可以支持TryParse。 //'If Not (Byte.TryParse(IpByte(i), TempByte4(3 - i))) Then //' TempByte4(3 - i) = &H0 //'End If if (IsNumeric(IpByte[i])) TempByte4[3 - i] = (byte)(Convert.ToInt32(IpByte[i]) & 0xff); } return BitConverter.ToUInt32(TempByte4, 0); } 看下,他怎么传递string IpValue这个值 private static string IntToIP(long ip_Int) { long num = (long)((ip_Int & 0xff000000L) >> 0x18); if (num < 0L) { num += 0x100L; } long num2 = (ip_Int & 0xff0000L) >> 0x10; if (num2 < 0L) { num2 += 0x100L; } long num3 = (ip_Int & 0xff00L) >> 8; if (num3 < 0L) { num3 += 0x100L; } long num4 = ip_Int & 0xffL; if (num4 < 0L) { num4 += 0x100L; } return (num.ToString() + "." + num2.ToString() + "." + num3.ToString() + "." + num4.ToString()); }public static string IntToIP(uint ipAddress) { long ui1 = ipAddress & 0xFF000000; ui1 = ui1 >> 24; long ui2 = ipAddress & 0x00FF0000; ui2 = ui2 >> 16; long ui3 = ipAddress & 0x0000FF00; ui3 = ui3 >> 8; long ui4 = ipAddress & 0x000000FF; string IPstr = ""; IPstr = System.Convert.ToString(ui1) + "." + System.Convert.ToString(ui2) + "." + System.Convert.ToString(ui3) + "." + System.Convert.ToString(ui4); return IPstr; } 求助:winform里如何设计如下界面,在线等 如何用公钥加密,私钥解密 Web数据采集,有证书验证,有用户名密码怎么采集阿? SOS!字符串连接 怎样在winform中的textbox里显示sql2000表中的一条记录中的一个字段?在线等待... 求助! 怎么读取配置文件(C#) C#访问SQL ,超简单,拜托高手指教 我可以学C#吗? 虚函数调用时必须要写明参数吗? 求大家帮我挑挑错 谁给来个算法问题啊
Search_Set = IndexInfoAtPos(Search_Index_Set);
//区间尾
Search_End = IndexInfoAtPos(Search_Index_End);
看看这两个值
也不是一条条“IP、国家、地区” 这样的信息。
它IP是用UInt32 来表示的。你要把这个UInt32表示的IP,转成"0.0.0.0"形式。其中IndexInfoAtPos(i).Offset就是这个UInt32吧。。没有仔细研究过这个库
[ip]是7个字节 4节点是起始ip 3个节点是结束ip(也叫上限)他的ip址址转成uint的代码如下
public UInt32 IPToUInt32(string IpValue)
{
string[] IpByte = IpValue.Split('.');
Int32 nUpperBound = IpByte.GetUpperBound(0);
if (nUpperBound != 3)
{
IpByte = new string[4];
for (Int32 i = 1; i <= 3 - nUpperBound; i++)
IpByte[nUpperBound + i] = "0";
} byte[] TempByte4 = new byte[4];
for (Int32 i = 0; i <= 3; i++)
{
//'如果是.Net 2.0可以支持TryParse。
//'If Not (Byte.TryParse(IpByte(i), TempByte4(3 - i))) Then
//' TempByte4(3 - i) = &H0
//'End If
if (IsNumeric(IpByte[i]))
TempByte4[3 - i] = (byte)(Convert.ToInt32(IpByte[i]) & 0xff);
} return BitConverter.ToUInt32(TempByte4, 0);
}
{
long num = (long)((ip_Int & 0xff000000L) >> 0x18);
if (num < 0L)
{
num += 0x100L;
}
long num2 = (ip_Int & 0xff0000L) >> 0x10;
if (num2 < 0L)
{
num2 += 0x100L;
}
long num3 = (ip_Int & 0xff00L) >> 8;
if (num3 < 0L)
{
num3 += 0x100L;
}
long num4 = ip_Int & 0xffL;
if (num4 < 0L)
{
num4 += 0x100L;
}
return (num.ToString() + "." + num2.ToString() + "." + num3.ToString() + "." + num4.ToString());
}
public static string IntToIP(uint ipAddress)
{
long ui1 = ipAddress & 0xFF000000;
ui1 = ui1 >> 24;
long ui2 = ipAddress & 0x00FF0000;
ui2 = ui2 >> 16;
long ui3 = ipAddress & 0x0000FF00;
ui3 = ui3 >> 8;
long ui4 = ipAddress & 0x000000FF;
string IPstr = "";
IPstr = System.Convert.ToString(ui1) + "." + System.Convert.ToString(ui2) + "." + System.Convert.ToString(ui3) + "." + System.Convert.ToString(ui4);
return IPstr;
}