Code Monkey home page Code Monkey logo

Comments (7)

geneliu avatar geneliu commented on July 28, 2024

This is very useful when the smart plug is in DHCP environment only.

from pyhs100.

rytilahti avatar rytilahti commented on July 28, 2024

In what format you would like to have it? The sys_info returned by the discovery already contains the mac, but the one from the wire (which is what you probably want?) is not exposed.

from pyhs100.

kdschlosser avatar kdschlosser commented on July 28, 2024

I have a nice little code piece that can obtain a devices true mac based on IP and without using subprocess to run ping and capture the output either :) funny thing is I just keyed it up about a week ago to send a WOL packet based on IP alone. So this can be done if it is something that the maintainers feel should be added or not. Or if it should be something the user should do themselves. But if you want the code for it drop a line. It's actually very small maybe 8 - 10 lines of code.

from pyhs100.

geneliu avatar geneliu commented on July 28, 2024

Thank you @rytilahti for your quick response! I found that both CLI and the static method of 'discover' have the mac data there already. The json format is pretty good. I think no code change/enhancement needed.

from pyhs100.

geneliu avatar geneliu commented on July 28, 2024

@kdschlosser
If you can post your code snippets somewhere or here that would be helpful.
Thanks,
Gene

from pyhs100.

kdschlosser avatar kdschlosser commented on July 28, 2024

here is the code for getting the mac address, it's a little longer then 10 lines but it is still very small

usage: print get_mac_address('192.168.1.1')

import struct
import ctypes


def get_mac_address(ip_address):
    arp = ctypes.windll.Iphlpapi.SendARP
    addr = ctypes.windll.wsock32.inet_addr(ip_address)

    hw_address = ctypes.c_buffer(6)
    add_long = ctypes.c_ulong(ctypes.sizeof(hw_address))

    arp(addr, 0, ctypes.byref(hw_address), ctypes.byref(add_long))

    res = []

    for val in struct.unpack('BBBBBB', hw_address):
        if val > 15:
            replace_str = '0x'
        else:
            replace_str = 'x'

        res.append(hex(val).replace(replace_str, '').upper())

    return ':'.join(res)

from pyhs100.

rytilahti avatar rytilahti commented on July 28, 2024

Closing this as MAC is available in the payload.

from pyhs100.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.