|
36 | 36 |
|
37 | 37 | def parse_scan_subnets(subnets): |
38 | 38 | """Extract subnet and interface from SCAN_SUBNETS""" |
| 39 | + |
39 | 40 | ranges = [] |
40 | 41 | interfaces = [] |
| 42 | + |
41 | 43 | for entry in subnets: |
42 | | - parts = entry.split("--interface=") |
43 | | - ranges.append(parts[0].strip()) |
44 | | - if len(parts) > 1: |
45 | | - interfaces.append(parts[1].strip()) |
| 44 | + |
| 45 | + # Extract interface |
| 46 | + interface_match = re.search(r'--interface=([^\s]+)', entry) |
| 47 | + interface = interface_match.group(1) if interface_match else None |
| 48 | + |
| 49 | + # Extract vlan |
| 50 | + vlan_match = re.search(r'--vlan=(\d+)', entry) |
| 51 | + vlan = vlan_match.group(1) if vlan_match else None |
| 52 | + |
| 53 | + # If VLAN interface exists, use it |
| 54 | + if interface and vlan: |
| 55 | + vlan_interface = f"{interface}.{vlan}" |
| 56 | + |
| 57 | + if os.path.exists(f"/sys/class/net/{vlan_interface}"): |
| 58 | + interface = vlan_interface |
| 59 | + mylog('verbose', [ |
| 60 | + f'[{pluginName}] Using VLAN interface: {interface}' |
| 61 | + ]) |
| 62 | + else: |
| 63 | + mylog('verbose', [ |
| 64 | + f'[{pluginName}] VLAN interface {vlan_interface} not found, using {interface}' |
| 65 | + ]) |
| 66 | + |
| 67 | + if interface: |
| 68 | + interfaces.append(interface) |
| 69 | + |
| 70 | + # Remove interface/vlan options from subnet definition |
| 71 | + subnet = re.sub(r'\s+--interface=[^\s]+', '', entry) |
| 72 | + subnet = re.sub(r'\s+--vlan=\d+', '', subnet) |
| 73 | + |
| 74 | + ranges.append(subnet.strip()) |
| 75 | + |
| 76 | + mylog('verbose', [f'[{pluginName}] SCAN_SUBNETS value: {subnets}']) |
| 77 | + mylog('verbose', [f'[{pluginName}] Parsed subnets: {ranges}']) |
| 78 | + mylog('verbose', [f'[{pluginName}] Parsed interfaces: {interfaces}']) |
| 79 | + |
46 | 80 | return ranges, interfaces |
47 | 81 |
|
48 | 82 |
|
|
0 commit comments