Adding Macs in bulk based on Mac range

Source: Internet
Author: User
You can enter a Mac range, batch add Mac such as input 11-22-33-44-[aa-ff]-55,1-2-3-34-4-4
will be mass production Mac
  1. /**
  2. * Convert to actual multiple ID array based on interval ID
  3. * @author in Brigitte
  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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.