(ip, chainCC=0)
return None
Return MAC address corresponding to a given IP address
Return MAC address corresponding to a given IP address
Return MAC address corresponding to a given IP address
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
def getmacbyip ( ip , chainCC = 0 ) : 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