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.
- /**
- * Convert to actual multiple id arrays based on interval id
- * @author Yu Yi
- * 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);
Copy code
|