Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netbios() and Python 3.8 #1476

Open
Casper133 opened this issue Feb 16, 2020 · 1 comment · May be fixed by #2406
Open

Netbios() and Python 3.8 #1476

Casper133 opened this issue Feb 16, 2020 · 1 comment · May be fixed by #2406

Comments

@Casper133
Copy link

Hi, I have a problem with Netbios function on Python 3.8

Expected behavior and actual behavior

I'm trying to get MAC-address using Netbios function from win32wnet module. But I get an error from library function:

Traceback (most recent call last):
  File "D:/Dev/PyCharmProjects/mac_address.py", line 33, in <module>
    print_mac_address()
  File "D:/Dev/PyCharmProjects/mac_address.py", line 14, in print_mac_address
    Netbios(ncb)
  File "C:\Users\Casper\AppData\Local\Programs\Python\Python38\lib\site-packages\win32\lib\netbios.py", line 187, in Netbios
    ob._pack()
  File "C:\Users\Casper\AppData\Local\Programs\Python\Python38\lib\site-packages\win32\lib\netbios.py", line 219, in _pack
    self._buffer_[:] = struct.pack(*(self._format,) + tuple(vals))
struct.error: argument for 's' must be a bytes object

Steps to reproduce the problem

I'm using this code:

# coding=utf-8

from netbios import NCB, NCBRESET, NCBASTAT, Netbios, ADAPTER_STATUS, byte_to_int, LANA_ENUM, NCBENUM, NRC_GOODRET


def print_mac_address():
    print("MAC-address:")

    ncb = NCB()

    ncb.Command = NCBENUM
    lana_numbers = LANA_ENUM()
    ncb.Buffer = lana_numbers
    Netbios(ncb)

    for i in range(lana_numbers.length):
        ncb.Command = NCBRESET
        ncb.Lana_num = byte_to_int(lana_numbers.lana[i])
        Netbios(ncb)

        ncb.Command = NCBASTAT
        ncb.Lana_num = byte_to_int(lana_numbers.lana[i])
        ncb.Callname = "*".encode("ascii")
        adapter_status = ADAPTER_STATUS()
        ncb.Buffer = adapter_status
        Netbios(ncb)

        if ncb.Retcode == NRC_GOODRET:
            for ch in adapter_status.adapter_address:
                print("%02x" % (byte_to_int(ch),), end=' ')


print_mac_address()

Version of Python and pywin32

Python: Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32

pywin32: pywin32 v227

@Casper133
Copy link
Author

Casper133 commented Feb 16, 2020

Also I tested code on Python 2.7 and it works fine:

# coding=utf-8

from netbios import NCB, NCBRESET, NCBASTAT, Netbios, ADAPTER_STATUS, byte_to_int, LANA_ENUM, NCBENUM, NRC_GOODRET


def print_mac_address():
    print "MAC-address:"

    ncb = NCB()

    ncb.Command = NCBENUM
    lana_numbers = LANA_ENUM()
    ncb.Buffer = lana_numbers
    Netbios(ncb)

    for i in range(lana_numbers.length):
        ncb.Command = NCBRESET
        ncb.Lana_num = byte_to_int(lana_numbers.lana[i])
        Netbios(ncb)

        ncb.Command = NCBASTAT
        ncb.Lana_num = byte_to_int(lana_numbers.lana[i])
        ncb.Callname = "*".encode("ascii")
        adapter_status = ADAPTER_STATUS()
        ncb.Buffer = adapter_status
        Netbios(ncb)

        if ncb.Retcode == NRC_GOODRET:
            print "-".join("%02X" % byte_to_int(address_part)
                           for address_part in adapter_status.adapter_address)


print_mac_address()

@Avasam Avasam linked a pull request Oct 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant