C#怎么把IP转换成长整型??
来源:百度知道 编辑:UC知道 时间:2024/05/28 05:16:29
IP是最长12位 加上 3个点。。
这样的话到底有什么意义呀
string ip = "192.168.1.111";
ip = ip.Replace(".","");
long ipLong = Convert.ToInt64(ip);//去掉.号
MessageBox.Show(ipLong.ToString());
IP转成长整型?
一般IP都存为字符型.
ip=ip.Replace(".","");
long intp=Convert.ToInt64(ip);
string ip = "192.168.0.1";
System.Net.IPAddress IP = System.Net.IPAddress.Parse(ip);
long aaa = ip.Address;
假设ip为:222.211.147.93
这我们把它看着一个类似255进制的“数”
93*255^0+147*255^1+211*255^2+222*255^3=一个长整型数
long ConvertIP(byte ip1, byte ip2, byte ip3, byte ip4)
{
//分别把 ip 255.255.255.255 放在long类型的 32-24位 24-16位 16-8位 8-0位
long ret = ip1 << 24 + ip2 << 16 + ip3 << 8 + ip4;
return ret;
}
string ip = "192.168.1.111";
ip = ip.Replace(&