Ip地址与十进制转化
2011-03-07 18:07
309 查看
<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>
<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数据库的应用--IP地址转化成十进制
- 指针实现字符串IP地址转化为十进制IP地址输出-c语言
- 将十进制ip地址转化为字符串点分十进制ip地址
- 纯真IP数据库的应用 IP地址转化成十进制
- 纯真IP数据库的应用 IP地址转化成十进制
- excel--转化IP地址为十进制
- 怎样快速对二进制和十进制进行互转化——IP地址规划与设计总结
- 十六进制转化为十进制
- 【zzuli】九进制转化为十进制
- 十进制转化为十六进制
- 十进制到十六进制转化的小函数
- 十进制转化成十六进制
- java数组操作3.十进制转化为2进制
- 『计算机组成原理』二进制转化十进制的简便方法(小节)
- 桟的应用——十进制转化为八进制
- 域名转化到IP地址的实现
- 把十进制转化为二进制的一种方法
- 利用DNS类.域名转化ip地址,利用ip地址转换域名
- IP地址转化为文本
- 《IP地址和数字之间转化的算法》