本文整理匯總了Python中scapy.config.conf.iface方法的典型用法代碼示例。如果您正苦於以下問題:Python conf.iface方法的具體用法?Python conf.iface怎麽用?Python conf.iface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scapy.config.conf
的用法示例。
在下文中一共展示了conf.iface方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: arping
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def arping(net, timeout=2, cache=0, verbose=None, **kargs):
"""Send ARP who-has requests to determine which hosts are up
arping(net, [cache=0,] [iface=conf.iface,] [verbose=conf.verb]) -> None
Set cache=True if you want arping to modify internal ARP-Cache"""
if verbose is None:
verbose = conf.verb
ans,unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=net), verbose=verbose,
filter="arp and arp[7] = 2", timeout=timeout, iface_hint=net, **kargs)
ans = ARPingResult(ans.res)
if cache and ans is not None:
for pair in ans:
arp_cache[pair[1].psrc] = (pair[1].hwsrc, time.time())
if verbose:
ans.show()
return ans,unans
示例2: send
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def send(self, x):
iff,a,gw = x.route()
if iff is None:
iff = conf.iface
sdto = (iff, self.type)
self.outs.bind(sdto)
sn = self.outs.getsockname()
ll = lambda x:x
if type(x) in conf.l3types:
sdto = (iff, conf.l3types[type(x)])
if sn[3] in conf.l2types:
ll = lambda x:conf.l2types[sn[3]]()/x
try:
sx = str(ll(x))
x.sent_time = time.time()
self.outs.sendto(sx, sdto)
except socket.error,msg:
x.sent_time = time.time() # bad approximation
if conf.auto_fragment and msg[0] == 90:
for p in x.fragment():
self.outs.sendto(str(ll(p)), sdto)
else:
raise
示例3: __init__
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def __init__(self, iface = None, type = ETH_P_ALL, promisc=None, filter=None):
self.type = type
self.outs = None
self.iface = iface
if iface is None:
iface = conf.iface
if promisc is None:
promisc = conf.sniff_promisc
self.promisc = promisc
self.ins = open_pcap(iface, 1600, self.promisc, 100)
try:
ioctl(self.ins.fileno(),BIOCIMMEDIATE,struct.pack("I",1))
except:
pass
if type == ETH_P_ALL: # Do not apply any filter if Ethernet type is given
if conf.except_filter:
if filter:
filter = "(%s) and not (%s)" % (filter, conf.except_filter)
else:
filter = "not (%s)" % conf.except_filter
if filter:
self.ins.setfilter(filter)
示例4: send
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def send(self, x):
iff,a,gw = x.route()
if iff is None:
iff = conf.iface
ifs,cls = self.iflist.get(iff,(None,None))
if ifs is None:
iftype = self.intf.get(iff)["type"]
if iftype == dnet.INTF_TYPE_ETH:
try:
cls = conf.l2types[1]
except KeyError:
warning("Unable to find Ethernet class. Using nothing")
ifs = dnet.eth(iff)
else:
ifs = dnet.ip()
self.iflist[iff] = ifs,cls
if cls is None:
sx = str(x)
else:
sx = str(cls()/x)
x.sent_time = time.time()
ifs.send(sx)
示例5: recv
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def recv(self,x=MTU):
ll = self.ins.datalink()
if ll in conf.l2types:
cls = conf.l2types[ll]
else:
cls = conf.default_l2
warning("Unable to guess datalink type (interface=%s linktype=%i). Using %s" % (self.iface, ll, cls.name))
pkt = self.ins.next()
if pkt is not None:
ts,pkt = pkt
if pkt is None:
return
try:
pkt = cls(pkt)
except KeyboardInterrupt:
raise
except:
if conf.debug_dissector:
raise
pkt = conf.raw_layer(pkt)
pkt.time = ts
return pkt.payload
示例6: __attrs_post_init__
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def __attrs_post_init__(self):
"""Initializes attributes after attrs __init__.
These attributes do not change during the life of the object.
"""
logger.debug('Creating new DHCPCAP obj.')
if self.iface is None:
self.iface = conf.iface
if self.client_mac is None:
_, client_mac = get_if_raw_hwaddr(self.iface)
self.client_mac = str2mac(client_mac)
if self.prl is None:
self.prl = PRL
if self.xid is None:
self.xid = gen_xid()
logger.debug('Modifying Lease obj, setting iface.')
self.lease.interface = self.iface
示例7: handle_offer_ack
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def handle_offer_ack(self, pkt, time_sent_request=None):
"""Create a lease object with the values in OFFER/ACK packet."""
attrs_dict = dict()
for opt in pkt[DHCP].options:
if isinstance(opt, tuple) and opt[0] in DHCP_OFFER_OPTIONS:
v = opt[1] if len(opt[1:]) < 2 else ' '.join(opt[1:])
v = str(v.decode('utf8')) if isinstance(v, bytes) else str(v)
attrs_dict[opt[0]] = v
attrs_dict.update({
"interface": self.iface,
"address": pkt[BOOTP].yiaddr,
"next_server": pkt[BOOTP].siaddr,
})
# this function changes the dict
self.gen_check_lease_attrs(attrs_dict)
logger.debug('Creating Lease obj.')
logger.debug('with attrs %s', attrs_dict)
lease = DHCPCAPLease(**attrs_dict)
return lease
示例8: reset
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def reset(self, iface=None, client_mac=None, xid=None, scriptfile=None):
"""Reset object attributes when state is INIT."""
logger.debug('Reseting attributes.')
if iface is None:
iface = conf.iface
if client_mac is None:
# scapy for python 3 returns byte, not tuple
tempmac = get_if_raw_hwaddr(iface)
if isinstance(tempmac, tuple) and len(tempmac) == 2:
mac = tempmac[1]
else:
mac = tempmac
client_mac = str2mac(mac)
self.client = DHCPCAP(iface=iface, client_mac=client_mac, xid=xid)
if scriptfile is not None:
self.script = ClientScript(scriptfile)
else:
self.script = None
self.time_sent_request = None
self.discover_attempts = 0
self.request_attempts = 0
self.current_state = STATE_PREINIT
self.offers = list()
示例9: send_discover
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def send_discover(self):
"""Send discover."""
assert self.client
assert self.current_state == STATE_INIT or \
self.current_state == STATE_SELECTING
pkt = self.client.gen_discover()
sendp(pkt)
# FIXME:20 check that this is correct,: all or only discover?
if self.discover_attempts < MAX_ATTEMPTS_DISCOVER:
self.discover_attempts += 1
timeout = gen_timeout_resend(self.discover_attempts)
self.set_timeout(self.current_state,
self.timeout_selecting,
timeout)
# logger.info('DHCPDISCOVER on %s to %s port %s' %
# (self.client.iface, self.client.server_mac,
# self.client.server_port)))
示例10: BOUND
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def BOUND(self):
"""BOUND state."""
logger.debug('In state: BOUND')
logger.info('(%s) state changed %s -> bound', self.client.iface,
STATES2NAMES[self.current_state])
self.current_state = STATE_BOUND
self.client.lease.info_lease()
if self.script is not None:
self.script.script_init(self.client.lease, self.current_state)
self.script.script_go()
else:
try:
set_net(self.client.lease)
except Exception as e:
logger.error('Can not set IP', exc_info=True)
# raise self.END()
# TODO: go daemon?
示例11: arping
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def arping(net, timeout=2, cache=0, verbose=None, **kargs):
"""Send ARP who-has requests to determine which hosts are up
arping(net, [cache=0,] [iface=conf.iface,] [verbose=conf.verb]) -> None
Set cache=True if you want arping to modify internal ARP-Cache"""
if verbose is None:
verbose = conf.verb
ans,unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=net), verbose=verbose,
filter="arp and arp[7] = 2", timeout=timeout, iface_hint=net, **kargs)
ans = ARPingResult(ans.res)
if cache and ans is not None:
for pair in ans:
conf.netcache.arp_cache[pair[1].psrc] = (pair[1].hwsrc, time.time())
if verbose:
ans.show()
return ans,unans
示例12: __repr__
# 需要導入模塊: from scapy.config import conf [as 別名]
# 或者: from scapy.config.conf import iface [as 別名]
def __repr__(self):
rtlst = []
for net, msk, gw, iface, cset, metric in self.routes:
rtlst.append(('%s/%i' % (net, msk),
gw,
(iface if isinstance(iface, six.string_types)
else iface.description),
", ".join(cset) if len(cset) > 0 else "",
str(metric)))
return pretty_list(rtlst,
[('Destination', 'Next Hop', "Iface", "Src candidates", "Metric")], # noqa: E501
sortBy=1)
# Unlike Scapy's Route.make_route() function, we do not have 'host' and 'net' # noqa: E501
# parameters. We only have a 'dst' parameter that accepts 'prefix' and
# 'prefix/prefixlen' values.
# WARNING: Providing a specific device will at the moment not work correctly. # noqa: E501