- 51Aspx源码必读.txt[4KB]
- from.gif[4KB]
- IPLibrary.sln[2KB]
- 最新Asp.Net源码下载.url[123B]
源码介绍
IP地址段转换为掩码源码
源码描述:
IP地址段转换为掩码
代码片段:
string yanma = "";
string startIPbinary = ConvertToBinary(startIP);//将IP转换成二进制,格式00000000.00000000.00000000.00000000.
string stopIPbinary = ConvertToBinary(stopIP);//将IP转换成二进制
string[] startIPs = startIPbinary.Split(new[] {'.'});//将转换好的二进制,以“.”分割成字符串数组。
string[] endIPs = stopIPbinary.Split(new[] { '.' });//将转换好的二进制,以“.”分割成字符串数组。
for (int i = 0; i < 4; i++)
{
if (startIPs[i] == endIPs[i])
{
yanma += 255.ToString()+".";
}
else
{
char[] startIPchar = StringToChar(startIPs[i].ToString());
char[] stopIPchar = StringToChar(endIPs[i].ToString());
int count = 0;
for (int j = 0; j < 8; j++)
{
if (stopIPchar[j] == startIPchar[j])
{
count++;
}
else
break;
}
double h = 0;
for (int k = 7; k >=8 - count; k--)
{
h += Math.Pow(2, k);
}
yanma += h.ToString();
break;
}
}
if (yanma.Split(new[] {'.'}).Length != 4)
{
for (int i = 0; i < 4 - yanma.Split(new[] {'.'}).Length; i++)
{
yanma += ".0";
}
}
return yanma;
}
源码描述:
IP地址段转换为掩码
代码片段:
string yanma = "";
string startIPbinary = ConvertToBinary(startIP);//将IP转换成二进制,格式00000000.00000000.00000000.00000000.
string stopIPbinary = ConvertToBinary(stopIP);//将IP转换成二进制
string[] startIPs = startIPbinary.Split(new[] {'.'});//将转换好的二进制,以“.”分割成字符串数组。
string[] endIPs = stopIPbinary.Split(new[] { '.' });//将转换好的二进制,以“.”分割成字符串数组。
for (int i = 0; i < 4; i++)
{
if (startIPs[i] == endIPs[i])
{
yanma += 255.ToString()+".";
}
else
{
char[] startIPchar = StringToChar(startIPs[i].ToString());
char[] stopIPchar = StringToChar(endIPs[i].ToString());
int count = 0;
for (int j = 0; j < 8; j++)
{
if (stopIPchar[j] == startIPchar[j])
{
count++;
}
else
break;
}
double h = 0;
for (int k = 7; k >=8 - count; k--)
{
h += Math.Pow(2, k);
}
yanma += h.ToString();
break;
}
}
if (yanma.Split(new[] {'.'}).Length != 4)
{
for (int i = 0; i < 4 - yanma.Split(new[] {'.'}).Length; i++)
{
yanma += ".0";
}
}
return yanma;
}
责任编辑:xiao
下载记录(Only Recent 100)
用户名 | 推荐指数 | 下载时间 |
---|