本文整理汇总了Python中scapy.layers.l2.Ether方法的典型用法代码示例。如果您正苦于以下问题:Python l2.Ether方法的具体用法?Python l2.Ether怎么用?Python l2.Ether使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scapy.layers.l2
的用法示例。
在下文中一共展示了l2.Ether方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_reply
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def make_reply(self, req):
mac = req.src
if type(self.pool) is list:
if not self.leases.has_key(mac):
self.leases[mac] = self.pool.pop()
ip = self.leases[mac]
else:
ip = self.pool
repb = req.getlayer(BOOTP).copy()
repb.op="BOOTREPLY"
repb.yiaddr = ip
repb.siaddr = self.gw
repb.ciaddr = self.gw
repb.giaddr = self.gw
del(repb.payload)
rep=Ether(dst=mac)/IP(dst=ip)/UDP(sport=req.dport,dport=req.sport)/repb
return rep
示例2: handle_ack
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def handle_ack(self, pkt, time_sent_request):
"""."""
logger.debug("Handling ACK.")
logger.debug('Modifying obj DHCPCAP, setting server data.')
self.server_mac = pkt[Ether].src
self.server_ip = pkt[IP].src
self.server_port = pkt[UDP].sport
event = DHCP_EVENTS['IP_ACQUIRE']
# FIXME:0 check the fields match the previously offered ones?
# FIXME:50 create a new object also on renewing/rebinding
# or only set_times?
lease = self.handle_offer_ack(pkt, time_sent_request)
lease.set_times(time_sent_request)
if self.lease is not None:
if (self.lease.address != lease.address or
self.lease.subnet_mask != lease.subnet_mask or
self.lease.router != lease.router):
event = DHCP_EVENTS['IP_CHANGE']
else:
event = DHCP_EVENTS['RENEW']
logger.debug('Modifying obj DHCPCAP, setting lease, client ip, event.')
self.lease = lease
self.client_ip = self.lease.address
self.event = event
return event
示例3: deal_common_pkt
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def deal_common_pkt(self, pkt):
# Send to DHCP server
# LLC / SNAP to Ether
if SNAP in pkt:
ether_pkt = Ether(src=self.client, dst=self.mac) / pkt[SNAP].payload # noqa: E501
self.dhcp_server.reply(ether_pkt)
# If an ARP request is made, extract client IP and answer
if ARP in pkt and \
pkt[ARP].op == 1 and pkt[ARP].pdst == self.dhcp_server.gw:
if self.arp_target_ip is None:
self.arp_target_ip = pkt[ARP].psrc
log_runtime.info("Detected IP: %s", self.arp_target_ip)
# Reply
ARP_ans = LLC() / SNAP() / ARP(
op="is-at",
psrc=self.arp_source_ip,
pdst=self.arp_target_ip,
hwsrc=self.mac,
hwdst=self.client,
)
self.send_wpa_to_client(ARP_ans)
# States
示例4: make_reply
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def make_reply(self, req):
mac = req[Ether].src
if isinstance(self.pool, list):
if mac not in self.leases:
self.leases[mac] = self.pool.pop()
ip = self.leases[mac]
else:
ip = self.pool
repb = req.getlayer(BOOTP).copy()
repb.op = "BOOTREPLY"
repb.yiaddr = ip
repb.siaddr = self.gw
repb.ciaddr = self.gw
repb.giaddr = self.gw
del(repb.payload)
rep = Ether(dst=mac) / IP(dst=ip) / UDP(sport=req.dport, dport=req.sport) / repb # noqa: E501
return rep
示例5: guess_payload_class
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def guess_payload_class(self, payload):
if len(payload) >= 1:
if not self.s:
return MPLS
ip_version = (orb(payload[0]) >> 4) & 0xF
if ip_version == 4:
return IP
elif ip_version == 5:
return BIER
elif ip_version == 6:
return IPv6
else:
if orb(payload[0]) == 0 and orb(payload[1]) == 0:
return EoMCW
else:
return Ether
return Padding
示例6: _get_underlayers_size
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def _get_underlayers_size(self):
"""
get the total size of all under layers
:return: number of bytes
"""
under_layer = self.underlayer
under_layers_size = 0
while under_layer and isinstance(under_layer, Dot1Q):
under_layers_size += 4
under_layer = under_layer.underlayer
if under_layer and isinstance(under_layer, Ether):
# ether header len + FCS len
under_layers_size += 14 + 4
return under_layers_size
示例7: make_reply
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def make_reply(self, req):
mac = req.src
if type(self.pool) is list:
if not mac in self.leases:
self.leases[mac] = self.pool.pop()
ip = self.leases[mac]
else:
ip = self.pool
repb = req.getlayer(BOOTP).copy()
repb.op="BOOTREPLY"
repb.yiaddr = ip
repb.siaddr = self.gw
repb.ciaddr = self.gw
repb.giaddr = self.gw
del(repb.payload)
rep=Ether(dst=mac)/IP(dst=ip)/UDP(sport=req.dport,dport=req.sport)/repb
return rep
示例8: decode_packet
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def decode_packet(self, packet):
from scapy.layers.l2 import Ether
try:
message = json.loads(packet)
self.log.debug('message', message=message)
for field in ['url', 'evc-map-name', 'total-len', 'port-number', 'message-contents']:
assert field in message, "Missing field '{}' in received packet".format(field)
decoded = message['message-contents'].decode('base64')
assert len(decoded.encode('hex'))/2 == message['total-len'], \
'Decoded length ({}) != Message Encoded length ({})'.\
format(len(decoded.encode('hex')), message['total-len'])
return int(message['port-number']), message['evc-map-name'], Ether(decoded)
except Exception as e:
self.log.exception('decode', e=e)
raise
示例9: decode_query_response_packet
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def decode_query_response_packet(self, packet, map_name=None):
"""
Create query-request to get all installed exceptions
:param map_name: (str) EVC-MAP Name (None=all)
:param packet: returned query response packet
:return: list of evcmaps and associated exceptions
"""
from scapy.layers.l2 import Ether
message = json.loads(packet)
self.log.debug('message', message=message)
if 'url' in message and message['url'] == 'adtran-olt-of-control/evc-map-response':
maps=message['evc-map-list']
if maps is not None:
self.log.debug('evc-maps-query-response', maps=maps)
return maps
return []
示例10: receive_packet_out
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def receive_packet_out(self, logical_device_id, egress_port_no, msg):
log.info('packet-out', logical_device_id=logical_device_id,
egress_port_no=egress_port_no, msg_len=len(msg))
_, logical_dev_id, _ = self.vlan_to_device_ids[egress_port_no]
if logical_dev_id != logical_device_id:
raise Exception('Internal table mismatch')
tmp = Ether(msg)
frame = Ether(dst=tmp.dst, src=tmp.src) / \
Dot1Q(vlan=TIBIT_PACKET_OUT_VLAN) / \
Dot1Q(vlan=egress_port_no) / \
tmp.payload
self.io_port.send(str(frame))
示例11: rcv_io
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def rcv_io(self, port, frame):
self.log.info('received', iface_name=port.iface_name,
frame_len=len(frame))
pkt = Ether(frame)
if pkt.haslayer(Dot1Q):
outer_shim = pkt.getlayer(Dot1Q)
if isinstance(outer_shim.payload, Dot1Q):
inner_shim = outer_shim.payload
cvid = inner_shim.vlan
logical_port = cvid
popped_frame = (
Ether(src=pkt.src, dst=pkt.dst, type=inner_shim.type) /
inner_shim.payload
)
kw = dict(
logical_device_id=self.logical_device_id,
logical_port_no=logical_port,
)
self.log.info('sending-packet-in', **kw)
self.adapter_agent.send_packet_in(
packet=str(popped_frame), **kw)
示例12: handle_packet_in
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def handle_packet_in(self, ind_info):
self.log.info('Received-Packet-In', ind_info=ind_info)
# LLDP packet trap from the NNI port is a special case.
# The logical port cannot be derived from the pon_id and
# gem_port. But, the BAL flow_id for the LLDP packet is
# fixed. Hence, check this flow_id and do the necessary
# handling.
if ind_info['flow_id'] == ASFVOLT16_LLDP_DL_FLOW_ID:
logical_port = MIN_ASFVOLT_NNI_LOGICAL_PORT_NUM + \
ind_info['intf_id']
else:
logical_port = self.get_logical_port_from_pon_id_and_gem_port(
ind_info['intf_id'],
ind_info['svc_port'])
if not logical_port:
self.log.error("uni-logical_port-not-found")
return
pkt = Ether(ind_info['packet'])
kw = dict(
logical_device_id=self.logical_device_id,
logical_port_no=logical_port,
)
self.log.info('sending-packet-in', **kw)
self.adapter_agent.send_packet_in(packet=str(pkt), **kw)
示例13: dhcp_request
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def dhcp_request(iface=None,**kargs):
if conf.checkIPaddr != 0:
warning("conf.checkIPaddr is not 0, I may not be able to match the answer")
if iface is None:
iface = conf.iface
fam,hw = get_if_raw_hwaddr(iface)
return srp1(Ether(dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0",dst="255.255.255.255")/UDP(sport=68,dport=67)
/BOOTP(chaddr=hw)/DHCP(options=[("message-type","discover"),"end"]),iface=iface,**kargs)
示例14: getmacbyip
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def getmacbyip(ip, chainCC=0):
"""Return MAC address corresponding to a given IP address"""
if isinstance(ip,Net):
ip = iter(ip).next()
tmp = map(ord, inet_aton(ip))
if (tmp[0] & 0xf0) == 0xe0: # mcast @
return "01:00:5e:%.2x:%.2x:%.2x" % (tmp[1]&0x7f,tmp[2],tmp[3])
iff,a,gw = conf.route.route(ip)
if ( (iff == LOOPBACK_NAME) or (ip == conf.route.get_if_bcast(iff)) ):
return "ff:ff:ff:ff:ff:ff"
# Windows uses local IP instead of 0.0.0.0 to represent locally reachable addresses
ifip = str(pcapdnet.dnet.intf().get(iff)['addr'])
if gw != ifip.split('/')[0]:
ip = gw
mac = conf.netcache.arp_cache.get(ip)
if mac:
return mac
res = srp1(Ether(dst=ETHER_BROADCAST)/ARP(op="who-has", pdst=ip),
type=ETH_P_ARP,
iface = iff,
timeout=2,
verbose=0,
chainCC=chainCC,
nofilter=1)
if res is not None:
mac = res.payload.hwsrc
conf.netcache.arp_cache[ip] = mac
return mac
return None
示例15: gen_ether_ip
# 需要导入模块: from scapy.layers import l2 [as 别名]
# 或者: from scapy.layers.l2 import Ether [as 别名]
def gen_ether_ip(self):
"""Generates link layer and IP layer part of DHCP packet.
For broadcast packets is:
Ether(src=client_mac, dst="ff:ff:ff:ff:ff:ff") /
IP(src="0.0.0.0", dst="255.255.255.255") /
"""
ether_ip = (Ether(src=self.client_mac, dst=BROADCAST_MAC) /
IP(src=META_ADDR, dst=BROADCAST_ADDR))
return ether_ip