首页 > 开发 > PHP > 正文

ip网段转换程序,把ip地址转换成相对就的整数

2024-05-04 21:58:27
字体:
来源:转载
供稿:网友
  1. mysql_connect('localhost','root','root'); 
  2. mysql_select_db('dfd'); 
  3.  
  4. $array = file("ip.txt"); 
  5. foreach$array as $k  ) 
  6.  list ($ip,$s) = explode('/',$k); 
  7.  $ipe = str_replace('.0','.255',$ip); 
  8.  $ipint = iptoint($ip); 
  9.  $ipinte = iptoint($ipe);  
  10.  //echo iptoint($ip) .'-'.iptoint($ipe),'<br />';//开源代码Vevb.com 
  11.  $s = array($ip,$ipe,$ipint,$ipinte); 
  12.  save($s); 
  13.  
  14. function iptoint($ip
  15.     $ipa=explode(".",$ip); 
  16.     $ipn=$ipa[0]*16777216+$ipa[1]*65536+$ipa[2]*256+$ipa[3]; 
  17.     return $ipn
  18.  
  19. function save($arr
  20.  ifcount$arr ) >3 ) 
  21.  { 
  22.   print_r($arr); 
  23.   mysql_query("insert into ip(ips教程,ipe,ipsint,ipeint)values('".$arr[0]."','".$arr[1]."','".$arr[2]."','".$arr[3]."')"or die(mysql_error()); 
  24.  } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表