日期:2014-05-16 浏览次数:20499 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>new document</title> <script type="text/javascript"> function ip2num(ip){ var arr = ip.split("."), x = 1, ret = 0; for(var i = 0; i < arr.length; i++){ ret += arr[i] * x; x *= 256; } return ret; } function num2ip(n){ var ret = [], x = 256 * 256 * 256; for(var i = 0; i < 4; i++){ ret.push(parseInt(n / x)); n %= x; x /= 256; } return ret.reverse().join("."); } var n = ip2num("192.168.1.228"); alert(n); alert(num2ip(n)); </script> </head> <body> </body> </html>