Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions scapy/arch/windows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

from glob import glob
import shlex
import os
import platform as platform_lib
import socket
Expand Down Expand Up @@ -207,15 +208,16 @@ def _reload(self):
env="SystemRoot")


def _exec_cmd(command):
# type: (str) -> Tuple[bytes, int]
"""Call a CMD command and return the output and returncode"""
proc = sp.Popen(command,
stdout=sp.PIPE,
shell=True)
res = proc.communicate()[0]
return res, proc.returncode

def _exec_cmd(command):
# type: (str) -> Tuple[bytes, int]
"""Call a CMD command and return the output and returncode"""
proc = sp.Popen(
shlex.split(command) if isinstance(command, str) else command,
stdout=sp.PIPE,
shell=False
)
res = proc.communicate()[0]
return res, proc.returncode

conf.prog = WinProgPath()

Expand Down Expand Up @@ -363,15 +365,16 @@ def _check_npcap_requirement(self):
if not self.raw80211:
raise Scapy_Exception("Npcap 802.11 support is NOT enabled !")


def _npcap_set(self, key, val):
# type: (str, str) -> bool
"""Internal function. Set a [key] parameter to [value]"""
if self.guid is None:
raise OSError("Interface not setup")
res, code = _exec_cmd(_encapsulate_admin(
" ".join([_WlanHelper, self.guid[1:-1], key, val])
))
_windows_title() # Reset title of the window
res, code = _exec_cmd(
[_WlanHelper, self.guid[1:-1], key, val]
)
_windows_title()
if code != 0:
raise OSError(res.decode("utf8", errors="ignore"))
return True
Expand All @@ -380,7 +383,7 @@ def _npcap_get(self, key):
# type: (str) -> str
if self.guid is None:
raise OSError("Interface not setup")
res, code = _exec_cmd(" ".join([_WlanHelper, self.guid[1:-1], key]))
res, code = _exec_cmd([_WlanHelper, self.guid[1:-1], key])
_windows_title() # Reset title of the window
if code != 0:
raise OSError(res.decode("utf8", errors="ignore"))
Expand Down