Issue
I am looking for a python way grab the client's MAC address. All requests are over the same network. I am looking for something similar to perform arp -n <Client_IP>
on the router.
Solution
Not sure but you can always get IP address using the request object like
request.remote_addr
and for that you have to
import request
and then you can pass this IP to this function
import netifaces as nif
def mac_for_ip(ip):
'Returns a list of MACs for interfaces that have given IP, returns None if not found'
for i in nif.interfaces():
addrs = nif.ifaddresses(i)
try:
if_mac = addrs[nif.AF_LINK][0]['addr']
if_ip = addrs[nif.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
from kursancew's answer to Getting MAC Address.
Answered By - Yogesh D
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.