Python scapy.all.get_if_hwaddr() Examples

The following are 6 code examples of scapy.all.get_if_hwaddr(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module scapy.all , or try the search function .
Example #1
Source File: utils.py    From iot-inspector-client with MIT License 6 votes vote down vote up
def get_my_mac_set(iface_filter=None):
    """Returns a set of MAC addresses of the current host."""

    out_set = set()
    if sys.platform.startswith("win"):
        from scapy.arch.windows import NetworkInterface
        if type(iface_filter) == NetworkInterface:
            out_set.add(iface_filter.mac)

    for iface in sc.get_if_list():
        if iface_filter is not None and iface != iface_filter:
            continue
        try:
            mac = sc.get_if_hwaddr(iface)
        except Exception as e:
            continue
        else:
            out_set.add(mac)

    return out_set 
Example #2
Source File: utils.py    From MITMf with GNU General Public License v3.0 6 votes vote down vote up
def get_mac(interface):
    try:
        mac_address = get_if_hwaddr(interface)
        return mac_address
    except Exception as e:
        shutdown("Error retrieving MAC address from {}: {}".format(interface, e)) 
Example #3
Source File: send.py    From p4-utils with GNU General Public License v2.0 5 votes vote down vote up
def main():

    if len(sys.argv)<3:
        print 'pass 2 arguments: <destination> "<message>"'
        exit(1)

    addr = socket.gethostbyname(sys.argv[1])
    iface = get_if()

    print "sending on interface %s to %s" % (iface, str(addr))
    pkt =  Ether(src=get_if_hwaddr(iface), dst='ff:ff:ff:ff:ff:ff')
    pkt = pkt /IP(dst=addr) / TCP(dport=1234, sport=random.randint(49152,65535)) / sys.argv[2]
    pkt.show2()
    sendp(pkt, iface=iface, verbose=False) 
Example #4
Source File: utils.py    From piSociEty with GNU General Public License v3.0 5 votes vote down vote up
def get_mac(interface):
    try:
        mac_address = get_if_hwaddr(interface)
        return mac_address
    except Exception as e:
        shutdown("Error retrieving MAC address from {}: {}".format(interface, e)) 
Example #5
Source File: poison.py    From polymorph with GNU General Public License v2.0 5 votes vote down vote up
def get_mac(self):
        try:
            mac_address = get_if_hwaddr(self._iface)
            return mac_address
        except Exception as e:
            print("Error retrieving MAC address from {}: {}".format(self._iface, e)) 
Example #6
Source File: arpspoof.py    From HomeAssistant-CustomComponents with Apache License 2.0 5 votes vote down vote up
def get_default_gateway_mac(self, interface):
        try:
            return get_if_hwaddr(interface)
        except OSError as e:
            _LOGGER.error(
                "Error when trying to get MAC of router on interface '%s': %s",
                e.args[1])

        return None