예제 #1
0
파일: uuid.py 프로젝트: ufofor/Sean-Kang
def _netbios_getnode():
    """Get the hardware address on Windows using NetBIOS calls.
    See http://support.microsoft.com/kb/118623 for details."""
    import win32wnet, netbios
    first_local_mac = None
    ncb = netbios.NCB()
    ncb.Command = netbios.NCBENUM
    ncb.Buffer = adapters = netbios.LANA_ENUM()
    adapters._pack()
    if win32wnet.Netbios(ncb) != 0:
        return None
    adapters._unpack()
    for i in range(adapters.length):
        ncb.Reset()
        ncb.Command = netbios.NCBRESET
        ncb.Lana_num = ord(adapters.lana[i])
        if win32wnet.Netbios(ncb) != 0:
            continue
        ncb.Reset()
        ncb.Command = netbios.NCBASTAT
        ncb.Lana_num = ord(adapters.lana[i])
        ncb.Callname = '*'.ljust(16)
        ncb.Buffer = status = netbios.ADAPTER_STATUS()
        if win32wnet.Netbios(ncb) != 0:
            continue
        status._unpack()
        bytes = status.adapter_address[:6]
        if len(bytes) != 6:
            continue
        mac = int.from_bytes(bytes, 'big')
        if _is_universal(mac):
            return mac
        first_local_mac = first_local_mac or mac
    return first_local_mac or None
예제 #2
0
파일: uuid.py 프로젝트: KittoFlora/t-imp
def _netbios_getnode():
    """Get the hardware address on Windows using NetBIOS calls.
    See http://support.microsoft.com/kb/118623 for details."""
    import win32wnet, netbios
    ncb = netbios.NCB()
    ncb.Command = netbios.NCBENUM
    ncb.Buffer = adapters = netbios.LANA_ENUM()
    adapters._pack()
    if win32wnet.Netbios(ncb) != 0:
        return
    adapters._unpack()
    for i in range(adapters.length):
        ncb.Reset()
        ncb.Command = netbios.NCBRESET
        ncb.Lana_num = ord(adapters.lana[i])
        if win32wnet.Netbios(ncb) != 0:
            continue
        ncb.Reset()
        ncb.Command = netbios.NCBASTAT
        ncb.Lana_num = ord(adapters.lana[i])
        ncb.Callname = '*'.ljust(16)
        ncb.Buffer = status = netbios.ADAPTER_STATUS()
        if win32wnet.Netbios(ncb) != 0:
            continue
        status._unpack()
        bytes = map(ord, status.adapter_address)
        return ((bytes[0] << 40L) + (bytes[1] << 32L) + (bytes[2] << 24L) +
                (bytes[3] << 16L) + (bytes[4] << 8L) + bytes[5])
예제 #3
0
파일: iplib.py 프로젝트: faune/synpy
    def _netbios_macs():
        # get MAC addresses from NetBIOS.  See
        # <http://support.microsoft.com/kb/118623>.
        try:
            import netbios
            from win32wnet import Netbios

            ncb = netbios.NCB()
            ncb.Command = netbios.NCBENUM
            ncb.Buffer = a = netbios.LANA_ENUM()
            a._pack()
            if Netbios(ncb) == 0:
                a._unpack()
                for i in range(a.length):
                    ncb.Reset()
                    ncb.Command = netbios.NCBRESET
                    ncb.Lana_num = _byte(a.lana[i])
                    if Netbios(ncb) == 0:
                        ncb.Reset()
                        ncb.Command = netbios.NCBASTAT
                        ncb.Lana_num = _byte(a.lana[i])
                        ncb.Callname = '*'.ljust(16)
                        ncb.Buffer = s = netbios.ADAPTER_STATUS()
                        if Netbios(ncb) == 0:
                            s._unpack()
                            yield isMAC(_bytes2int(s.adapter_address[:6]))
        except (ImportError, AttributeError):
            pass
예제 #4
0
def getUserMachine(netbiosname,type=3):
    ncb = netbios.NCB()
    
    # find a lana number to be used 
    ncb.Command = netbios.NCBENUM
    ncb.Buffer = la_enum = netbios.LANA_ENUM()
    rc = netbios.Netbios(ncb)
    if rc != 0: raise RuntimeError, "Netbios lan enum error. " + NetBiosErrorMap[rc]
    lanaNo = ord(la_enum.lana[0]) # using first number found always
    
    # perform a netbios reset, dont know why but must be done!
    ncb.Reset()
    ncb.Command = netbios.NCBRESET
    ncb.Lana_num = lanaNo
    rc = netbios.Netbios(ncb)
    if rc != 0: raise RuntimeError, "Netbios reset error. " + NetBiosErrorMap[rc]
    
    # perform a netbios name query to find the username  
    name = netbiosname.upper().ljust(15) + chr(type)
    ncb.Callname = name
    ncb.Lana_num = lanaNo    
    ncb.Command = netbios.NCBFINDNAME
    ncb.Buffer = adapter = FIND_HEADER_BUFFER()
    rc = netbios.Netbios(ncb)
    if rc != 0: raise RuntimeError, "Netbios findname error. " + NetBiosErrorMap[rc]
    return getHostname(convertIP(adapter.destination_addr))
예제 #5
0
파일: uuid.py 프로젝트: R4M80MrX/eve-1
def _netbios_getnode():
    import win32wnet, netbios
    ncb = netbios.NCB()
    ncb.Command = netbios.NCBENUM
    ncb.Buffer = adapters = netbios.LANA_ENUM()
    adapters._pack()
    if win32wnet.Netbios(ncb) != 0:
        return
    adapters._unpack()
    for i in range(adapters.length):
        ncb.Reset()
        ncb.Command = netbios.NCBRESET
        ncb.Lana_num = ord(adapters.lana[i])
        if win32wnet.Netbios(ncb) != 0:
            continue
        ncb.Reset()
        ncb.Command = netbios.NCBASTAT
        ncb.Lana_num = ord(adapters.lana[i])
        ncb.Callname = '*'.ljust(16)
        ncb.Buffer = status = netbios.ADAPTER_STATUS()
        if win32wnet.Netbios(ncb) != 0:
            continue
        status._unpack()
        bytes = map(ord, status.adapter_address)
        return (bytes[0] << 40L) + (bytes[1] << 32L) + (bytes[2] << 24L) + (bytes[3] << 16L) + (bytes[4] << 8L) + bytes[5]
예제 #6
0
def _netbios_getnode():
    import win32wnet
    import netbios
    ncb = netbios.NCB()
    ncb.Command = netbios.NCBENUM
    ncb.Buffer = adapters = netbios.LANA_ENUM()
    adapters._pack()
    if win32wnet.Netbios(ncb) != 0:
        return
    adapters._unpack()
    for i in range(adapters.length):
        ncb.Reset()
        ncb.Command = netbios.NCBRESET
        ncb.Lana_num = ord(adapters.lana[i])
        if win32wnet.Netbios(ncb) != 0:
            pass
        ncb.Reset()
        ncb.Command = netbios.NCBASTAT
        ncb.Lana_num = ord(adapters.lana[i])
        ncb.Callname = '*'.ljust(16)
        ncb.Buffer = status = netbios.ADAPTER_STATUS()
        if win32wnet.Netbios(ncb) != 0:
            pass
        status._unpack()
        bytes = status.adapter_address
예제 #7
0
 def testNetbios(self):
     # taken from the demo code in netbios.py
     ncb = win32wnet.NCB()
     ncb.Command = netbios.NCBENUM
     la_enum = netbios.LANA_ENUM()
     ncb.Buffer = la_enum
     rc = win32wnet.Netbios(ncb)
     self.assertEqual(rc, 0)
     for i in range(la_enum.length):
         ncb.Reset()
         ncb.Command = netbios.NCBRESET
         ncb.Lana_num = netbios.byte_to_int(la_enum.lana[i])
         rc = Netbios(ncb)
         self.assertEqual(rc, 0)
         ncb.Reset()
         ncb.Command = netbios.NCBASTAT
         ncb.Lana_num = byte_to_int(la_enum.lana[i])
         ncb.Callname = str2bytes("*               ")  # ensure bytes on py2x and 3k
         adapter = netbios.ADAPTER_STATUS()
         ncb.Buffer = adapter
         Netbios(ncb)
         # expect 6 bytes in the mac address.
         self.assertTrue(len(adapter.adapter_address), 6)