本文整理汇总了Python中scapy.error.log_loading.info方法的典型用法代码示例。如果您正苦于以下问题:Python log_loading.info方法的具体用法?Python log_loading.info怎么用?Python log_loading.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scapy.error.log_loading
的用法示例。
在下文中一共展示了log_loading.info方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [as 别名]
def update(self, data):
"""Update info about network interface according to given dnet dictionary"""
self.name = data["name"]
self.description = data['description']
self.win_index = data['win_index']
# Other attributes are optional
if conf.use_winpcapy:
self._update_pcapdata()
try:
self.ip = socket.inet_ntoa(get_if_raw_addr(data['guid']))
except (KeyError, AttributeError, NameError):
pass
try:
self.mac = data['mac']
except KeyError:
pass
示例2: update
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [as 别名]
def update(self, dnetdict):
"""Update info about network interface according to given dnet dictionary"""
self.name = dnetdict["name"]
# Other attributes are optional
try:
self.ip = socket.inet_ntoa(dnetdict["addr"].ip)
except (KeyError, AttributeError, NameError):
pass
try:
self.mac = dnetdict["link_addr"]
except KeyError:
pass
self._update_pcapdata()
示例3: resync
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [as 别名]
def resync(self):
# TODO : At the moment, resync will drop existing Teredo routes
# if any. Change that ...
self.invalidate_cache()
self.routes = read_routes6()
self.ipv6_ifaces = set()
for route in self.routes:
self.ipv6_ifaces.add(route[3])
if self.routes == []:
log_loading.info("No IPv6 support in kernel")
示例4: load_protocols
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [as 别名]
def load_protocols(filename, _fallback=None, _integer_base=10, _cls=DADict):
""""Parse /etc/protocols and return values as a dictionary."""
spaces = re.compile(b"[ \t]+|\n")
dct = _cls(_name=filename)
def _process_data(fdesc):
for line in fdesc:
try:
shrp = line.find(b"#")
if shrp >= 0:
line = line[:shrp]
line = line.strip()
if not line:
continue
lt = tuple(re.split(spaces, line))
if len(lt) < 2 or not lt[0]:
continue
dct[int(lt[1], _integer_base)] = fixname(lt[0])
except Exception as e:
log_loading.info(
"Couldn't parse file [%s]: line [%r] (%s)",
filename,
line,
e,
)
try:
if not filename:
raise IOError
with open(filename, "rb") as fdesc:
_process_data(fdesc)
except IOError:
if _fallback:
_process_data(_fallback.split(b"\n"))
else:
log_loading.info("Can't open %s file", filename)
return dct
示例5: mysummary
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [as 别名]
def mysummary(self):
if self.ID == 0:
ssid = repr(self.info)
if ssid[:2] in ['b"', "b'"]:
ssid = ssid[1:]
return "SSID=%s" % ssid, [Dot11]
else:
return ""
示例6: pre_dissect
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [as 别名]
def pre_dissect(self, s):
# Backward compatibility: add info to all elements
# This allows to introduce new Dot11Elt classes without breaking
# previous code
if len(s) >= 3:
length = orb(s[1])
if length > 0 and length <= 255:
self.info = s[2:2 + length]
return s
示例7: _pcap_check
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [as 别名]
def _pcap_check(cls):
"""Performs checks/restart pcap adapter"""
if not conf.use_pcap:
# Winpcap/Npcap isn't installed
return
_detect = pcap_service_status()
def _ask_user():
if not conf.interactive:
return False
msg = "Do you want to start it ? (yes/no) [y]: "
try:
# Better IPython compatibility
import IPython
return IPython.utils.io.ask_yes_no(msg, default='y')
except (NameError, ImportError):
while True:
_confir = input(msg)
_confir = _confir.lower().strip()
if _confir in ["yes", "y", ""]:
return True
elif _confir in ["no", "n"]:
return False
if _detect:
# No action needed
return
else:
warning(
"Scapy has detected that your pcap service is not running !"
)
if not conf.interactive or _ask_user():
succeed = pcap_service_start(askadmin=conf.interactive)
if succeed:
log_loading.info("Pcap service started !")
return
warning("Could not start the pcap service ! "
"You probably won't be able to send packets. "
"Deactivating unneeded interfaces and restarting "
"Scapy might help. Check your winpcap/npcap installation "
"and access rights.")
示例8: _update_pcapdata
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [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
示例9: load_services
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [as 别名]
def load_services(filename):
spaces = re.compile(b"[ \t]+|\n")
tdct = DADict(_name="%s-tcp" % filename)
udct = DADict(_name="%s-udp" % filename)
try:
with open(filename, "rb") as fdesc:
for line in fdesc:
try:
shrp = line.find(b"#")
if shrp >= 0:
line = line[:shrp]
line = line.strip()
if not line:
continue
lt = tuple(re.split(spaces, line))
if len(lt) < 2 or not lt[0]:
continue
dtct = None
if lt[1].endswith(b"/tcp"):
dtct = tdct
elif lt[1].endswith(b"/udp"):
dtct = udct
else:
continue
port = lt[1].split(b'/')[0]
name = fixname(lt[0])
if b"-" in port:
sport, eport = port.split(b"-")
for i in range(int(sport), int(eport) + 1):
dtct[i] = name
else:
dtct[int(port)] = name
except Exception as e:
log_loading.warning(
"Couldn't parse file [%s]: line [%r] (%s)",
filename,
line,
e,
)
except IOError:
log_loading.info("Can't open /etc/services file")
return tdct, udct
示例10: sniff
# 需要导入模块: from scapy.error import log_loading [as 别名]
# 或者: from scapy.error.log_loading import info [as 别名]
def sniff(count=0, store=1, offline=None, prn = None, lfilter=None, L2socket=None, timeout=None, *arg, **karg):
"""Sniff packets
sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + L2ListenSocket args) -> list of packets
Select interface to sniff by setting conf.iface. Use show_interfaces() to see interface names.
count: number of packets to capture. 0 means infinity
store: wether to store sniffed packets or discard them
prn: function to apply to each packet. If something is returned,
it is displayed. Ex:
ex: prn = lambda x: x.summary()
lfilter: python function applied to each packet to determine
if further action may be done
ex: lfilter = lambda x: x.haslayer(Padding)
offline: pcap file to read packets from, instead of sniffing them
timeout: stop sniffing after a given time (default: None)
L2socket: use the provided L2socket
"""
c = 0
if offline is None:
log_runtime.info('Sniffing on %s' % conf.iface)
if L2socket is None:
L2socket = conf.L2listen
s = L2socket(type=ETH_P_ALL, *arg, **karg)
else:
s = PcapReader(offline)
lst = []
if timeout is not None:
stoptime = time.time()+timeout
remain = None
while 1:
try:
if timeout is not None:
remain = stoptime-time.time()
if remain <= 0:
break
try:
p = s.recv(MTU)
except PcapTimeoutElapsed:
continue
if p is None:
break
if lfilter and not lfilter(p):
continue
if store:
lst.append(p)
c += 1
if prn:
r = prn(p)
if r is not None:
print(r)
if count > 0 and c >= count:
break
except KeyboardInterrupt:
break
s.close()
return plist.PacketList(lst,"Sniffed")