草鞋

Blog grass shoes
posts - 1, comments - 4, trackbacks - 0, articles - 27
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

IP地址转换数值(匹配IP地址的正则表达式)

Posted on 2007-10-23 09:29 草 鞋 阅读(523) 评论(0)  编辑  收藏 所属分类: JavaScript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> new document </title>
  <meta name="generator" content="editplus" />
  <meta name="author" content="" />
  <meta name="keywords" content="" />
  <meta name="description" content="" />
 </head>
 <body>
  <script type="text/javascript">
  <!--
 function IP2V(ip)
 {
  re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g  //匹配IP地址的正则表达式
  if(re.test(ip))
  {
   return RegExp.$1*Math.pow(255,3)+RegExp.$2*Math.pow(255,2)+RegExp.$3*255+RegExp.$4*1;
  }
  else
  {
   throw new Error("Not a valid IP address!")
  }
 }
  var i = IP2V("192.168.60.1");
  alert(i);
//-->
  </script>
 </body>
</html>