ether2any/helper.py

25 lines
511 B
Python
Raw Normal View History

2011-10-30 01:22:45 +02:00
def getSrcMacFromPkt(packet):
if len(packet) < 16:
return None
return packet[10:16]
def getDstMacFromPkt(packet):
if len(packet) < 10:
return None
return packet[4:10]
def binToHexStr(binmac):
return "".join(["%02x" % ord(i) for i in binmac])
# checks if packet is a broadcast packet
def isBroadcast(packet):
binmac = getDstMacFromPkt(packet)
# normal broadcast
if binmac == '\xff\xff\xff\xff\xff\xff':
return True
# v6 multicast
if binmac.startswith('\x33\x33'):
return True
return False