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
- /**
- * Convert an array of multiple IDs based on the interval id
- * @ Author at callback
- * February 10, 2014 15:29:09
- */
- Class BatchConvertDeviceId {
- Public static function convert ($ str_str ){
- $ Str_str = str_replace (',', $ str_str );
- $ Arr_ids = explode (',', $ str_str );
- $ Arr_re = array ();
- Foreach ($ arr_ids as $ str_str ){
- $ Arr_arr = preg_split ("/\ [([^ \ [\] +) \]/", $ str_str, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
- $ Int_count = count ($ arr_arr );
- $ Arr_data = array ();
- If ($ int_count = 1 ){
- $ Arr_data = $ arr_arr;
- } Else {
- For ($ I = 0; $ I <$ int_count; $ I ++ ){
- If ($ I % 2 = 0 ){
- $ Arr_data = self: batchLink ($ arr_data, array ($ arr_arr [$ I]);
- } Else {
- Self: batchConvert ($ arr_data, $ arr_arr [$ I]);
- }
- }
- }
- $ Arr_re = array_merge ($ arr_re, $ arr_data );
- }
- Return $ arr_re;
- }
- Private static function batchConvert (& $ arr, $ str ){
- $ Arr_str = explode ('-', $ str );
- $ Int_start = base_convert ($ arr_str [0], 16, 10 );
- $ Int_end = base_convert ($ arr_str [1], 16, 10 );
- $ Int_min = $ int_start <$ int_end? $ Int_start: $ int_end;
- $ Int_max = $ int_start> $ int_end? $ Int_start: $ int_end;
- For ($ int_min; $ int_min <= $ int_max; $ int_min ++ ){
- $ _ Arr_str [] = base_convert ($ int_min, 10, 16 );
- }
- $ Arr = self: batchLink ($ arr, $ _ arr_str );
- }
- Private static function batchLink ($ arr, $ arr_str ){
- $ Arr_re = array ();
- If (! Empty ($ arr )){
- Foreach ($ arr as $ _ v1 ){
- Foreach ($ arr_str as $ _ v2 ){
- $ Arr_re [] =$ _ v1. $ _ v2;
- }
- }
- } Else {
- $ Arr_re = $ arr_str;
- }
- Return $ arr_re;
- }
- }
- // $ Str = "ab-cd-33-22-aa-[11-13]-[AB-ac]";
- //
- // $ Arr = BatchConvertDeviceId: convert ($ str );
- // Echo'
'; - //print_r($arr);
|