當前位置: 首頁>>代碼示例>>Python>>正文


Python arch.get_if_hwaddr方法代碼示例

本文整理匯總了Python中scapy.arch.get_if_hwaddr方法的典型用法代碼示例。如果您正苦於以下問題:Python arch.get_if_hwaddr方法的具體用法?Python arch.get_if_hwaddr怎麽用?Python arch.get_if_hwaddr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scapy.arch的用法示例。


在下文中一共展示了arch.get_if_hwaddr方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_reply

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def make_reply(self, req):
        ether = req.getlayer(Ether)
        arp = req.getlayer(ARP)

        if 'iface' in self.optsend:
            iff = self.optsend.get('iface')
        else:
            iff, a, gw = conf.route.route(arp.psrc)
        self.iff = iff
        if self.ARP_addr is None:
            try:
                ARP_addr = get_if_hwaddr(iff)
            except Exception:
                ARP_addr = "00:00:00:00:00:00"
        else:
            ARP_addr = self.ARP_addr
        resp = Ether(dst=ether.src,
                     src=ARP_addr) / ARP(op="is-at",
                                         hwsrc=ARP_addr,
                                         psrc=arp.pdst,
                                         hwdst=arp.hwsrc,
                                         pdst=arp.psrc)
        return resp 
開發者ID:secdev,項目名稱:scapy,代碼行數:25,代碼來源:l2.py

示例2: neighsol

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def neighsol(addr, src, iface, timeout=1, chainCC=0):
    """Sends and receive an ICMPv6 Neighbor Solicitation message

    This function sends an ICMPv6 Neighbor Solicitation message
    to get the MAC address of the neighbor with specified IPv6 address address.

    'src' address is used as source of the message. Message is sent on iface.
    By default, timeout waiting for an answer is 1 second.

    If no answer is gathered, None is returned. Else, the answer is
    returned (ethernet frame).
    """

    nsma = in6_getnsma(inet_pton(socket.AF_INET6, addr))
    d = inet_ntop(socket.AF_INET6, nsma)
    dm = in6_getnsmac(nsma)
    p = Ether(dst=dm) / IPv6(dst=d, src=src, hlim=255)
    p /= ICMPv6ND_NS(tgt=addr)
    p /= ICMPv6NDOptSrcLLAddr(lladdr=get_if_hwaddr(iface))
    res = srp1(p, type=ETH_P_IPV6, iface=iface, timeout=1, verbose=0,
               chainCC=chainCC)

    return res 
開發者ID:secdev,項目名稱:scapy,代碼行數:25,代碼來源:inet6.py

示例3: i2h

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def i2h(self, pkt, x):
        if x is None:
            iff,a,gw = pkt.payload.route()
            if iff:
                try:
                    x = get_if_hwaddr(iff)
                except:
                    pass
            if x is None:
                x = "00:00:00:00:00:00"
        return MACField.i2h(self, pkt, x) 
開發者ID:medbenali,項目名稱:CyberScan,代碼行數:13,代碼來源:l2.py

示例4: i2h

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def i2h(self, pkt, x):
        if x is None:
            iff = self.getif(pkt)
            if iff is None:
                iff = conf.iface
            if iff:
                try:
                    x = get_if_hwaddr(iff)
                except Exception as e:
                    warning("Could not get the source MAC: %s" % e)
            if x is None:
                x = "00:00:00:00:00:00"
        return MACField.i2h(self, pkt, x) 
開發者ID:secdev,項目名稱:scapy,代碼行數:15,代碼來源:l2.py

示例5: command_scan

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def command_scan(self, *args, **kwargs):
        conf.verb = self.verbose
        self.sniff_mac_address = get_if_hwaddr(self.nic)
        p = threading.Thread(target=self.sniff_answer)
        p.setDaemon(True)
        p.start()
        self._send_scan_packet(target_mac=PROFINET_BROADCAST_ADDRESS_1)
        self._send_scan_packet(target_mac=PROFINET_BROADCAST_ADDRESS_2)
        self.sniff_finished.wait(self.timeout + 1)
        unique_device = [list(x) for x in set(tuple(x) for x in self.result)]
        print_table(TABLE_HEADER, *unique_device)
        print('\n') 
開發者ID:dark-lbp,項目名稱:isf,代碼行數:14,代碼來源:profinet_set_ip.py

示例6: run

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def run(self):
        conf.verb = self.verbose
        self.sniff_mac_address = get_if_hwaddr(self.nic)
        self.scan_target_ip(self.target)
        if len(self.result) == 0:
            print_error("Didn't find any device, please check target mac address.")
            return
        print_status("Please make sure target device info is correct.")
        print_status("Do you want setup target with\n ip address: %s\n network mask: %s\n gateway:%s\n" % (
            self.target_ip, self.target_netmask, self.target_gateway
        ))
        ans = raw_input("Y/y to confirm, other to cancel.\n:")
        if ans.upper() == "Y":
            self.exploit(target_mac=self.target)
            self.scan_target_ip(self.target)
            # TODO: need some other method to check setup is success or not.
            if len(self.result) == 0:
                print_error("Setup target ip failed.")
                return

            if self.result[0][3] != self.target_ip \
                    or self.result[0][4] != self.target_netmask \
                    or self.result[0][5] != self.target_gateway:
                print_error("Setup target ip failed.")
                return
            else:
                print_success("Setup target ip succeed") 
開發者ID:dark-lbp,項目名稱:isf,代碼行數:29,代碼來源:profinet_set_ip.py

示例7: run

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def run(self):
        conf.verb = self.verbose
        self.sniff_mac_address = get_if_hwaddr(self.nic)
        p = threading.Thread(target=self.sniff_answer)
        p.setDaemon(True)
        p.start()
        self.exploit(target_mac=PROFINET_BROADCAST_ADDRESS_1)
        self.exploit(target_mac=PROFINET_BROADCAST_ADDRESS_2)
        self.sniff_finished.wait(self.timeout + 1)
        unique_device = [list(x) for x in set(tuple(x) for x in self.result)]
        print_table(TABLE_HEADER, *unique_device) 
開發者ID:dark-lbp,項目名稱:isf,代碼行數:13,代碼來源:profinet_dcp_scan.py

示例8: discover_local_device

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def discover_local_device(self):
        self.sniff_mac_address = get_if_hwaddr(self.nic)
        p = threading.Thread(target=self.sniff_answer)
        p.setDaemon(True)
        p.start()
        # wait sniff start
        time.sleep(0.2)
        packet = Ether(src=self.sniff_mac_address, dst="ff:ff:ff:ff:ff:ff")/IP(src=get_if_addr(self.nic), dst="255.255.255.255")/UDP(sport=44818, dport=44818)/ENIPHeader(Command=0x0063)
        sendp(packet, iface=self.nic)
        self.sniff_finished.wait(self.timeout + 1) 
開發者ID:dark-lbp,項目名稱:isf,代碼行數:12,代碼來源:enip_scan.py

示例9: arpleak

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def arpleak(target, plen=255, hwlen=255, **kargs):
    """Exploit ARP leak flaws, like NetBSD-SA2017-002.

https://ftp.netbsd.org/pub/NetBSD/security/advisories/NetBSD-SA2017-002.txt.asc

    """
    # We want explicit packets
    pkts_iface = {}
    for pkt in ARP(pdst=target):
        # We have to do some of Scapy's work since we mess with
        # important values
        iface = conf.route.route(pkt.pdst)[0]
        psrc = get_if_addr(iface)
        hwsrc = get_if_hwaddr(iface)
        pkt.plen = plen
        pkt.hwlen = hwlen
        if plen == 4:
            pkt.psrc = psrc
        else:
            pkt.psrc = inet_aton(psrc)[:plen]
            pkt.pdst = inet_aton(pkt.pdst)[:plen]
        if hwlen == 6:
            pkt.hwsrc = hwsrc
        else:
            pkt.hwsrc = mac2str(hwsrc)[:hwlen]
        pkts_iface.setdefault(iface, []).append(
            Ether(src=hwsrc, dst=ETHER_BROADCAST) / pkt
        )
    ans, unans = SndRcvList(), PacketList(name="Unanswered")
    for iface, pkts in viewitems(pkts_iface):
        ans_new, unans_new = srp(pkts, iface=iface, filter="arp", **kargs)
        ans += ans_new
        unans += unans_new
        ans.listname = "Results"
        unans.listname = "Unanswered"
    for _, rcv in ans:
        if ARP not in rcv:
            continue
        rcv = rcv[ARP]
        psrc = rcv.get_field('psrc').i2m(rcv, rcv.psrc)
        if plen > 4 and len(psrc) > 4:
            print("psrc")
            hexdump(psrc[4:])
            print()
        hwsrc = rcv.get_field('hwsrc').i2m(rcv, rcv.hwsrc)
        if hwlen > 6 and len(hwsrc) > 6:
            print("hwsrc")
            hexdump(hwsrc[6:])
            print()
    return ans, unans 
開發者ID:secdev,項目名稱:scapy,代碼行數:52,代碼來源:l2.py

示例10: _NDP_Attack_DAD_DoS

# 需要導入模塊: from scapy import arch [as 別名]
# 或者: from scapy.arch import get_if_hwaddr [as 別名]
def _NDP_Attack_DAD_DoS(reply_callback, iface=None, mac_src_filter=None,
                        tgt_filter=None, reply_mac=None):
    """
    Internal generic helper accepting a specific callback as first argument,
    for NS or NA reply. See the two specific functions below.
    """

    def is_request(req, mac_src_filter, tgt_filter):
        """
        Check if packet req is a request
        """

        # Those simple checks are based on Section 5.4.2 of RFC 4862
        if not (Ether in req and IPv6 in req and ICMPv6ND_NS in req):
            return 0

        # Get and compare the MAC address
        mac_src = req[Ether].src
        if mac_src_filter and mac_src != mac_src_filter:
            return 0

        # Source must be the unspecified address
        if req[IPv6].src != "::":
            return 0

        # Check destination is the link-local solicited-node multicast
        # address associated with target address in received NS
        tgt = inet_pton(socket.AF_INET6, req[ICMPv6ND_NS].tgt)
        if tgt_filter and tgt != tgt_filter:
            return 0
        received_snma = inet_pton(socket.AF_INET6, req[IPv6].dst)
        expected_snma = in6_getnsma(tgt)
        if received_snma != expected_snma:
            return 0

        return 1

    if not iface:
        iface = conf.iface

    # To prevent sniffing our own traffic
    if not reply_mac:
        reply_mac = get_if_hwaddr(iface)
    sniff_filter = "icmp6 and not ether src %s" % reply_mac

    sniff(store=0,
          filter=sniff_filter,
          lfilter=lambda x: is_request(x, mac_src_filter, tgt_filter),
          prn=lambda x: reply_callback(x, reply_mac, iface),
          iface=iface) 
開發者ID:secdev,項目名稱:scapy,代碼行數:52,代碼來源:inet6.py


注:本文中的scapy.arch.get_if_hwaddr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。