把ip地址转换成整数的js代码

发布时间:2019-08-30编辑:脚本学堂
本文介绍一段js代码,可以将IP地址转换成整数,有需要的朋友,参考下吧。

代码如下:
 

复制代码 代码示例:
<script>
/**
* IP地址转换为整数
* edit www.jb200.com
*/
function judge_ip(){  
startip=document.all.txt_startip.value
endip=document.all.txt_endip.value
alert('startip');
exit;
    //ipaddress to nint
IPAddress ip = IPAddress.Parse(startip);
Byte[] bytes = ip.GetAddressBytes();
uint start=bytes[0];
start = (s << 8) | ((uint)bytes[1]);
start = (s << 8) | ((uint)bytes[2]);
start = (s << 8) | ((uint)bytes[3]);
start_ip = start;
     
IPAddress ip = IPAddress.Parse(endip);
Byte[] bytes = ip.GetAddressBytes();
uint end=bytes[0];
end = (end << 8) | ((uint)bytes[1]);
end = (end << 8) | ((uint)bytes[2]);
end = (end << 8) | ((uint)bytes[3]);
end_ip = end;
      
if(end_ip>start_ip+65535){
alert('<{$lang_err_judge_ip}><{$lang_error_ip}>');
return false;
}
}
</script>