首页 > 开发 > 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. { 
  7.  list ($ip,$s) = explode('/',$k); 
  8.  $ipe = str_replace('.0','.255',$ip); 
  9.  $ipint = iptoint($ip); 
  10.  $ipinte = iptoint($ipe);  
  11.  //echo iptoint($ip) .'-'.iptoint($ipe),'<br />';//开源代码Vevb.com 
  12.  $s = array($ip,$ipe,$ipint,$ipinte); 
  13.  save($s); 
  14. } 
  15.  
  16. function iptoint($ip) 
  17. { 
  18.     $ipa=explode(".",$ip); 
  19.     $ipn=$ipa[0]*16777216+$ipa[1]*65536+$ipa[2]*256+$ipa[3]; 
  20.     return $ipn; 
  21. } 
  22.  
  23. function save($arr) 
  24. { 
  25.  if( count( $arr ) >3 ) 
  26.  { 
  27.   print_r($arr); 
  28.   mysql_query("insert into ip(ips教程,ipe,ipsint,ipeint)values('".$arr[0]."','".$arr[1]."','".$arr[2]."','".$arr[3]."')") or die(mysql_error()); 
  29.  } 
  30. } 

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