Batch add mac addresses based on mac ranges

Source: Internet
Author: User
Batch add mac addresses based on mac ranges
You can enter a mac range and add a mac in batches, for example, input 11-22-33-44-[aa-ff]-55,1-2-3-34-4-4
Batch production of mac

  1. /**
  2. * Convert an array of multiple IDs based on the interval id
  3. * @ Author at callback
  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);

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.