Best Python code snippet using lemoncheesecake
dataset_options.py
Source:dataset_options.py
1import re2class Option:3 @staticmethod4 def create(name, value=None, description=None, required=False, pattern=None):5 ALL_OPTIONS = {6 "rhost": RHOST,7 "lhost": LHOST,8 "timeout": Timeout,9 "rport": RPORT,10 "rports": RPORTS,11 "verbose": Verbose,12 "iface": Iface,13 "file": File,14 "uri": URI,15 "channel": Channel,16 "mac": MAC,17 "bssid": MAC,18 "bmac": MAC,19 "apishodan": SHODAN20 } 21 cl = ALL_OPTIONS.get(name, None)22 if cl:23 if description:24 return cl(value, required, description)25 else:26 return cl(value, required)27 else:28 return GenericOption(name, value, required, description, pattern)29# Generic Option Class30class GenericOption:31 def __init__(self, key=None, value=None, required=False, description=None, match_pattern=None):32 self.key = key33 self.value = value34 self.required = required35 self.description = description36 self.match_pattern = match_pattern37 38 def _check_pattern(self, v):39 if self.match_pattern is None or v is None:40 return True41 success = False42 if v:43 m = re.match(self.match_pattern, str(v))44 if m:45 success = True46 return success47 48 def set_value(self, v):49 success = self._check_pattern(v)50 if self._check_pattern(v):51 self.value = v52 return success53 54 def get_option(self):55 return {self.key:[self.value, self.description, self.required]}56# Specific Options Classes57class RHOST(GenericOption):58 def __init__(self, value=None, required=False, description="Remote host IP", 59 match_pattern=r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$|^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\\\d+$"):60 key="rhost"61 super(RHOST, self).__init__(key, value, required, description, match_pattern)62class LHOST(GenericOption):63 def __init__(self, value=None, required=False, description="Local host IP", 64 match_pattern=r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$|^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\\\d+$"):65 key="rhost"66 super(LHOST, self).__init__(key, value, required, description, match_pattern)67class RPORT(GenericOption):68 def __init__(self, value=None, required=False, 69 description="Remote port (Example: 80)", match_pattern=r"^\d+$"):70 key="rport"71 super(RPORT, self).__init__(key, value, required, description, match_pattern)72 73class LPORT(GenericOption):74 def __init__(self, value=None, required=False, 75 description="Local port (Example: 8080)", match_pattern=r"^\d+$"):76 key="lport"77 78 super(LPORT, self).__init__(key, value, required, description, match_pattern)79class RPORTS(GenericOption):80 def __init__(self, value=None, required=False, 81 description="Remote ports (Example: 100-500)", match_pattern=r"^\d+-\d+$"):82 key="rports"83 super(RPORTS, self).__init__(key, value, required, description, match_pattern)84class Timeout(GenericOption):85 def __init__(self, value=None, required=False, 86 description="Timeout to wait for search responses. (In seconds)", match_pattern=r"^\d+$"):87 key="timeout"88 super(Timeout, self).__init__(key, value, required, description, match_pattern)89class Verbose(GenericOption):90 def __init__(self, value=False, required=False, description="Show extra info while running module",91 match_pattern = r"^True|False|true|false|TRUE|FALSE$"):92 key="verbose"93 super(Verbose, self).__init__(key, value, required, description, match_pattern)94class Iface(GenericOption):95 def __init__(self, value=None, required=False, description="Network/Bluetooth interface", match_pattern=None): 96 key="iface"97 super(Iface, self).__init__(key, value, required, description, match_pattern)98class File(GenericOption):99 def __init__(self, value=None, required=False, description="File to dump or read the data", match_pattern=None):100 key="file"101 super(File, self).__init__(key, value, required, description, match_pattern)102class URI(GenericOption):103 def __init__(self, value=None, required=False, description="URI", 104 match_pattern = r"^http://|^https://|rtsp://|ftp://"):105 key="uri"106 super(URI, self).__init__(key, value, required, description, match_pattern)107class Channel(GenericOption):108 def __init__(self,value=None, required=False, description="Network channel. Configure this option if you want to fix it and not 'make jumps'", match_pattern=r"^\d{1,2}$"):109 key="channel"110 super(Channel, self).__init__(key, value, required, description, match_pattern)111class MAC(GenericOption):112 def __init__(self, value=None, required=False, description="Mac address", match_pattern=r"^(?:[0-9a-fA-F]:?){12}$"):113 key="mac"114 super(MAC, self).__init__(key, value, required, description, match_pattern)115class SHODAN(GenericOption):116 def __init__(self, value=None, required=False, description="Shodan API Key"):117 key="shodan"...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!