<html>
<head>
<title>IP转换</title>
<script>
function ip2long()
{
var ipv4=document.getElementById('aa').value;
var aIPsec=ipv4.split(".");
for(var i=0;i<4;i++)
{
if(parseInt(aIPsec[i])<16)
{
aIPsec[i]="0"+parseInt(aIPsec[i]).toString(16);
}
else
{
aIPsec[i]=parseInt(aIPsec[i]).toString(16);
}
}
var nIPaddr=parseInt("0x"+aIPsec[0]+aIPsec[1]+aIPsec[2]+aIPsec[3]);
document.getElementById('a').innerHTML=nIPaddr;
}
function long2ip ()
{
var proper_address=document.getElementById('bb').value;
var output = false;
if ( !isNaN ( proper_address ))
{
output = ( (proper_address>>24) & 0xff ) + '.' +( (proper_address>>16) & 0xff ) + '.' +( (proper_address>>8) & 0xff ) + '.' +( proper_address & 0xff );
}
document.getElementById('b').innerHTML=output;
}
</script>
</head>
<body>
<input type="text" id="aa" /><input type="button" onclick="ip2long()" value="IP转换为十进制" />
<div id='a'></div>
<input type="text" id="bb" /><input type="button" onclick="long2ip ()" value="十进制转换为IP" />
<div id='b'></div>
</body>
</html>
Ip地址与十进制转化
最新推荐文章于 2026-06-17 14:19:39 发布

6万+

被折叠的 条评论
为什么被折叠?



