Changeset View
Changeset View
Standalone View
Standalone View
scap/targets.py
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | if not patterns: | ||||
patterns = [pattern] | patterns = [pattern] | ||||
targets = [] | targets = [] | ||||
for pattern in patterns: | for pattern in patterns: | ||||
# remove any leading '!' | # remove any leading '!' | ||||
test_pattern = pattern.lstrip('!') | test_pattern = pattern.lstrip('!') | ||||
# change '.' to literal period | # change '.' to literal period | ||||
test_pattern = test_pattern.replace('.', '\.') | test_pattern = test_pattern.replace('.', r'\.') | ||||
# convert '*' to match a-Z, 0-9, _, -, or . | # convert '*' to match a-Z, 0-9, _, -, or . | ||||
test_pattern = test_pattern.replace('*', '[\w\.-]*') | test_pattern = test_pattern.replace('*', r'[\w\.-]*') | ||||
# Add beginning and end marks | # Add beginning and end marks | ||||
test_pattern = '^{}$'.format(test_pattern) | test_pattern = '^{}$'.format(test_pattern) | ||||
regex = re.compile(test_pattern) | regex = re.compile(test_pattern) | ||||
targets.extend([host for host in hosts if regex.match(host)]) | targets.extend([host for host in hosts if regex.match(host)]) | ||||
▲ Show 20 Lines • Show All 202 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 3.0 (CC-BY-SA) unless otherwise noted; code licensed under GNU General Public License (GPL) or other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct. · Wikimedia Foundation · Privacy Policy · Code of Conduct · Terms of Use · Disclaimer · CC-BY-SA · GPL