求将Access的IP数据库转为192.168.0.1格式的函数及最新的IP数据库 求一个将Access的IP1(10位),IP2(10位)格式的IP数据库转为192.168.0.1格式的函数(C#描述的)。谢谢!以及最新的IP数据库[email protected]谢谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 即是说数据库中有:IP1 IP2 国家 地区 1234567890 1234567890 XX XX这样的字段,如何用一个函数将IP1,IP2两个字段转换为192.168.0.1格式的。 IP地址库动网论坛数据库里就有如果IP1,IP2没有一定的规则,恐怕很难分解,因为IP地址分段数值取值范围太大,逐一分解比较困难 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时是如何做的???大家跟贴吧?学习学习!!! 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 bigintas 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--------------------------觉得好要给分 关于IP库现在我能得到的IP库太详细了,有些竟然有大学的第几楼第几室,或‘ADSL’用户我需要的只是ip1 ip2 国家 省市地区(一般是城市)要将那个ip 库进行合并呀,痛苦,有哪位高人有这种IP数据库 ghibrain(雨子杉): 你的程序是基于ip1 ip2 国家 省市地区(一般是城市)这种形式的吧???是不是??? 是一个储存过程吗?如何用,我还不会用储存过程啊??刚学不久。 ghibrain(雨子杉)兄弟,说说啊。 windows 8批处理 显示时间 大家帮忙看下下面的问题哪里错了? List<T>去重问题! 二天,终于完工了,大家帮着测测 asp.net 页面刷新后怎么让滚动条到底 求救:为何总是跳出输入密码的窗口? 十万火急!!!我公司网站用的是虚拟空间,现在换了一个提供商,数据库服务器也换了,我该怎么把以前的数据转到现在的服务器上?(分不够 Net.Mail发送邮件,附件变成了乱码(dat文件) MVC为什么不加载子对象的数据? 是中国人就来看 如何在web form中动态寻找对象 请问DATAGRID显示出数据后,每条记录怎么编辑?
1234567890 1234567890 XX XX
这样的字段,如何用一个函数将IP1,IP2两个字段转换为192.168.0.1格式的。
{
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时是如何做的???大家跟贴吧?学习学习!!!
//
// 将基于字符串的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
--------------------------
觉得好要给分
现在我能得到的IP库太详细了,有些竟然有大学的第几楼第几室,或‘ADSL’用户
我需要的只是
ip1 ip2 国家 省市地区(一般是城市)要将那个ip 库进行合并呀,痛苦,
有哪位高人有这种IP数据库
你的程序是基于ip1 ip2 国家 省市地区(一般是城市)这种形式的吧???是不是???
是一个储存过程吗?如何用,我还不会用储存过程啊??刚学不久。
兄弟,说说啊。