MCPcopy Index your code
hub / github.com/secdev/scapy / explore

Function explore

scapy/packet.py:2181–2366  ·  view source on GitHub ↗

Function used to discover the Scapy layers and protocols. It helps to see which packets exists in contrib or layer files. params: - layer: If specified, the function will explore the layer. If not, the GUI mode will be activated, to browse the available layers exampl

(layer=None)

Source from the content-addressed store, hash-verified

2179
2180@conf.commands.register
2181def explore(layer=None):
2182 # type: (Optional[str]) -> None
2183 """Function used to discover the Scapy layers and protocols.
2184 It helps to see which packets exists in contrib or layer files.
2185
2186 params:
2187 - layer: If specified, the function will explore the layer. If not,
2188 the GUI mode will be activated, to browse the available layers
2189
2190 examples:
2191 >>> explore() # Launches the GUI
2192 >>> explore("dns") # Explore scapy.layers.dns
2193 >>> explore("http2") # Explore scapy.contrib.http2
2194 >>> explore(scapy.layers.bluetooth4LE)
2195
2196 Note: to search a packet by name, use ls("name") rather than explore.
2197 """
2198 if layer is None: # GUI MODE
2199 if not conf.interactive:
2200 raise Scapy_Exception("explore() GUI-mode cannot be run in "
2201 "interactive mode. Please provide a "
2202 "'layer' parameter !")
2203 # 0 - Imports
2204 try:
2205 import prompt_toolkit
2206 except ImportError:
2207 raise ImportError("prompt_toolkit is not installed ! "
2208 "You may install IPython, which contains it, via"
2209 " `pip install ipython`")
2210 if not _version_checker(prompt_toolkit, (2, 0)):
2211 raise ImportError("prompt_toolkit >= 2.0.0 is required !")
2212 # Only available with prompt_toolkit > 2.0, not released on PyPi yet
2213 from prompt_toolkit.shortcuts.dialogs import radiolist_dialog, \
2214 button_dialog
2215 from prompt_toolkit.formatted_text import HTML
2216 # Check for prompt_toolkit >= 3.0.0
2217 call_ptk = lambda x: cast(str, x) # type: Callable[[Any], str]
2218 if _version_checker(prompt_toolkit, (3, 0)):
2219 call_ptk = lambda x: x.run()
2220 # 1 - Ask for layer or contrib
2221 btn_diag = button_dialog(
2222 title="Scapy v%s" % conf.version,
2223 text=HTML(
2224 '<style bg="white" fg="red">Chose the type of packets'
2225 ' you want to explore:</style>'
2226 ),
2227 buttons=[
2228 ("Layers", "layers"),
2229 ("Contribs", "contribs"),
2230 ("Cancel", "cancel")
2231 ])
2232 action = call_ptk(btn_diag)
2233 # 2 - Retrieve list of Packets
2234 if action == "layers":
2235 # Get all loaded layers
2236 lvalues = conf.layers.layers()
2237 # Restrict to layers-only (not contribs) + packet.py and asn1*.py
2238 values = [x for x in lvalues if ("layers" in x[0] or

Callers

nothing calls this directly

Calls 14

Scapy_ExceptionClass · 0.90
_version_checkerFunction · 0.90
list_contribFunction · 0.90
load_contribFunction · 0.90
warningFunction · 0.90
pretty_listFunction · 0.90
joinMethod · 0.80
popMethod · 0.80
replaceMethod · 0.80
runMethod · 0.45
layersMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected