Home > Backend Development > PHP Tutorial > Add mac in batches based on mac range

Add mac in batches based on mac range

WBOY
Release: 2016-07-25 08:48:47
Original
1035 people have browsed it
You can enter a mac range and add macs in batches. For example, enter 11-22-33-44-[aa-ff]-55,1-2-3-34-4-4
to batch produce macs.
  1. /**
  2. * Convert to actual multiple id arrays based on interval id
  3. * @author Yu Yi
  4. * February 10, 2014 15:29:09
  5. */
  6. class BatchConvertDeviceId {
  7. public static function convert($str_str) {
  8. $str_str = str_replace(',', ',',$str_str);
  9. $arr_ids = explode(',', $str_str);
  10. $arr_re=array();
  11. foreach ($arr_ids as $str_str) {
  12. $arr_arr = preg_split("/[([^[]]+)] /", $str_str, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  13. $int_count = count($arr_arr);
  14. $arr_data = array();
  15. if ($int_count == 1) {
  16. $arr_data = $arr_arr;
  17. } else {
  18. for ($i = 0; $i < $int_count; $i++) {
  19. if ($i % 2 == 0) {
  20. $arr_data = self::batchLink($arr_data, array($arr_arr[ $i]));
  21. } else {
  22. self::batchConvert($arr_data, $arr_arr[$i]);
  23. }
  24. }
  25. }
  26. $arr_re = array_merge($arr_re, $arr_data);
  27. }
  28. return $arr_re;
  29. }
  30. private static function batchConvert(&$arr, $str) {
  31. $arr_str = explode('-', $str);
  32. $int_start = base_convert($arr_str[0], 16, 10) ;
  33. $int_end = base_convert($arr_str[1], 16, 10);
  34. $int_min=$int_start<$int_end?$int_start:$int_end;
  35. $int_max=$int_start>$int_end?$int_start:$int_end;
  36. for ($int_min; $int_min <= $int_max; $int_min++) {
  37. $_arr_str[] = base_convert($int_min, 10, 16);
  38. }
  39. $arr = self::batchLink($arr, $_arr_str );
  40. }
  41. private static function batchLink($arr, $arr_str) {
  42. $arr_re = array();
  43. if (!empty($arr)) {
  44. foreach ($arr as $_v1) {
  45. foreach ( $arr_str as $_v2) {
  46. $arr_re[] = $_v1 . $_v2;
  47. }
  48. }
  49. } else {
  50. $arr_re = $arr_str;
  51. }
  52. return $arr_re;
  53. }
  54. }
  55. // $str = "ab-cd-33-22-aa-[11-13]-[ab-ac]";
  56. //
  57. //$arr = BatchConvertDeviceId::convert($str);
  58. //echo '
    ';
  59. //print_r($arr);
Copy code


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template