python Python obtener mac desde ip

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python obtener mac desde ip相关的知识,希望对你有一定的参考价值。

# Requiere instalar netifaces
import netifaces

def mac_for_ip(ip):
    """
    Returns a list of MACs for interfaces that have given IP, returns None if not found
    :param ip: string
    :return: if_mac|None: ip + mac
    """
    for i in netifaces.interfaces():
        addrs = netifaces.ifaddresses(i)
        try:
            if_mac = addrs[netifaces.AF_LINK][0]['addr']
            if_ip = addrs[netifaces.AF_INET][0]['addr']
        except (IndexError, KeyError): # ignore ifaces that dont have MAC or IP
            if_mac = if_ip = None
        if if_ip == ip:
            return if_mac
    return None


ip = '192.168.1.100'

print(mac_for_ip(ip))
# 50:a1:47:0c:ed:d8

以上是关于python Python obtener mac desde ip的主要内容,如果未能解决你的问题,请参考以下文章

php Obtener URL del home

java OBTENER OS

csharp obtener combo de matrix

text obtener sesion实际o bloqueo

sql MySQL obtener booleano como texto。

sql MySQL obtener booleano como texto。