本文整理匯總了Python中scapy.sendrecv.debug.match方法的典型用法代碼示例。如果您正苦於以下問題:Python debug.match方法的具體用法?Python debug.match怎麽用?Python debug.match使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scapy.sendrecv.debug
的用法示例。
在下文中一共展示了debug.match方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_from_dnet
# 需要導入模塊: from scapy.sendrecv import debug [as 別名]
# 或者: from scapy.sendrecv.debug import match [as 別名]
def load_from_dnet(self):
"""Populate interface table via dnet"""
for i in pcapdnet.dnet.intf():
try:
# XXX: Only Ethernet for the moment: localhost is not supported by dnet and pcap
# We only take interfaces that have an IP address, because the IP
# is used for the mapping between dnet and pcap interface names
# and this significantly improves Scapy's startup performance
if i["name"].startswith("eth") and "addr" in i:
self.data[i["name"]] = NetworkInterface(i)
except (KeyError, PcapNameNotFoundError):
pass
if len(self.data) == 0:
log_loading.warning("No match between your pcap and dnet network interfaces found. "
"You probably won't be able to send packets. "
"Deactivating unneeded interfaces and restarting Scapy might help.")
示例2: load_from_powershell
# 需要導入模塊: from scapy.sendrecv import debug [as 別名]
# 或者: from scapy.sendrecv.debug import match [as 別名]
def load_from_powershell(self):
for i in get_windows_if_list():
try:
interface = NetworkInterface(i)
self.data[interface.name] = interface
except (KeyError, PcapNameNotFoundError):
pass
if len(self.data) == 0:
log_loading.warning("No match between your pcap and windows network interfaces found. "
"You probably won't be able to send packets. "
"Deactivating unneeded interfaces and restarting Scapy might help."
"Check your winpcap and powershell installation, and access rights.")
示例3: _where
# 需要導入模塊: from scapy.sendrecv import debug [as 別名]
# 或者: from scapy.sendrecv.debug import match [as 別名]
def _where(filename, dirs=[], env="PATH"):
"""Find file in current dir or system path"""
if not isinstance(dirs, list):
dirs = [dirs]
if glob(filename):
return filename
paths = [os.curdir] + os.environ[env].split(os.path.pathsep) + dirs
for path in paths:
for match in glob(os.path.join(path, filename)):
if match:
return os.path.normpath(match)
raise IOError("File not found: %s" % filename)
示例4: read_routes
# 需要導入模塊: from scapy.sendrecv import debug [as 別名]
# 或者: from scapy.sendrecv.debug import match [as 別名]
def read_routes():
ok = 0
routes = []
ip = '(\d+\.\d+\.\d+\.\d+)'
# On Vista and Windows 7 the gateway can be IP or 'On-link'.
# But the exact 'On-link' string depends on the locale, so we allow any text.
gw_pattern = '(.+)'
metric_pattern = "(\d+)"
delim = "\s+" # The columns are separated by whitespace
netstat_line = delim.join([ip, ip, gw_pattern, ip, metric_pattern])
pattern = re.compile(netstat_line)
f=os.popen("netstat -rn")
for l in f.readlines():
match = re.search(pattern,l)
if match:
dest = match.group(1)
mask = match.group(2)
gw = match.group(3)
netif = match.group(4)
metric = match.group(5)
try:
intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest))
except OSError:
log_loading.warning("Building Scapy's routing table: Couldn't get outgoing interface for destination %s" % dest)
continue
if not intf.has_key("addr"):
break
addr = str(intf["addr"])
addr = addr.split("/")[0]
dest = atol(dest)
mask = atol(mask)
# If the gateway is no IP we assume it's on-link
gw_ipmatch = re.search('\d+\.\d+\.\d+\.\d+', gw)
if gw_ipmatch:
gw = gw_ipmatch.group(0)
else:
gw = netif
routes.append((dest,mask,gw, str(intf["name"]), addr))
f.close()
return routes
示例5: read_routes
# 需要導入模塊: from scapy.sendrecv import debug [as 別名]
# 或者: from scapy.sendrecv.debug import match [as 別名]
def read_routes():
routes = []
if_index = '(\d+)'
dest = '(\d+\.\d+\.\d+\.\d+)/(\d+)'
next_hop = '(\d+\.\d+\.\d+\.\d+)'
metric_pattern = "(\d+)"
delim = "\s+" # The columns are separated by whitespace
netstat_line = delim.join([if_index, dest, next_hop, metric_pattern])
pattern = re.compile(netstat_line)
# This works only starting from Windows 8/2012 and up. For older Windows another solution is needed
ps = sp.Popen(['powershell', 'Get-NetRoute', '-AddressFamily IPV4', '|', 'select ifIndex, DestinationPrefix, NextHop, RouteMetric'], stdout = sp.PIPE, universal_newlines = True)
stdout, stdin = ps.communicate(timeout = 10)
for l in stdout.split('\n'):
match = re.search(pattern,l)
if match:
try:
iface = devname_from_index(int(match.group(1)))
addr = ifaces[iface].ip
except:
continue
dest = atol(match.group(2))
mask = itom(int(match.group(3)))
gw = match.group(4)
# try:
# intf = pcapdnet.dnet.intf().get_dst(pcapdnet.dnet.addr(type=2, addrtxt=dest))
# except OSError:
# log_loading.warning("Building Scapy's routing table: Couldn't get outgoing interface for destination %s" % dest)
# continue
routes.append((dest, mask, gw, iface, addr))
return routes
示例6: _update_pcapdata
# 需要導入模塊: from scapy.sendrecv import debug [as 別名]
# 或者: from scapy.sendrecv.debug import match [as 別名]
def _update_pcapdata(self):
"""Supplement more info from pypcap and the Windows registry"""
# XXX: We try eth0 - eth29 by bruteforce and match by IP address,
# because only the IP is available in both pypcap and dnet.
# This may not work with unorthodox network configurations and is
# slow because we have to walk through the Windows registry.
for n in range(30):
guess = "eth%s" % n
win_name = pcapdnet.pcap.ex_name(guess)
if win_name.endswith("}"):
try:
uuid = win_name[win_name.index("{"):win_name.index("}")+1]
keyname = r"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\%s" % uuid
try:
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyname)
except WindowsError:
log_loading.debug("Couldn't open 'HKEY_LOCAL_MACHINE\\%s' (for guessed pcap iface name '%s')." % (keyname, guess))
continue
try:
fixed_ip = _winreg.QueryValueEx(key, "IPAddress")[0][0].encode("utf-8")
except (WindowsError, UnicodeDecodeError, IndexError):
fixed_ip = None
try:
dhcp_ip = _winreg.QueryValueEx(key, "DhcpIPAddress")[0].encode("utf-8")
except (WindowsError, UnicodeDecodeError, IndexError):
dhcp_ip = None
# "0.0.0.0" or None means the value is not set (at least not correctly).
# If both fixed_ip and dhcp_ip are set, fixed_ip takes precedence
if fixed_ip is not None and fixed_ip != "0.0.0.0":
ip = fixed_ip
elif dhcp_ip is not None and dhcp_ip != "0.0.0.0":
ip = dhcp_ip
else:
continue
except IOError:
continue
else:
if ip == self.ip:
self.pcap_name = guess
self.win_name = win_name
self.uuid = uuid
break
else:
raise PcapNameNotFoundError