Skip to main content

Overview

The nmb module provides a complete implementation of the NetBIOS Name Service (NBNS) protocol. It enables NetBIOS name resolution, node status queries, and NetBIOS session management over TCP and UDP.

Key Classes

NetBIOS

Main class for NetBIOS Name Service operations.
int
default:"137"
NetBIOS Name Service port number

Methods

gethostbyname()

Resolve a NetBIOS name to IP address.
str
required
NetBIOS name to resolve
int
default:"TYPE_WORKSTATION"
NetBIOS name type:
  • TYPE_WORKSTATION (0x00) - Workstation service
  • TYPE_SERVER (0x20) - File server service
  • TYPE_DOMAIN_MASTER (0x1B) - Domain master browser
  • TYPE_DOMAIN_CONTROLLER (0x1C) - Domain controller
  • TYPE_MASTER_BROWSER (0x1D) - Master browser
str
NetBIOS scope identifier (rarely used)
int
default:"1"
Query timeout in seconds
NBPositiveNameQueryResponse
Object containing IP addresses for the name

getnodestatus()

Query node status information.
str
required
NetBIOS name to query (use '*' for any name)
str
IP address to send query to. If None, uses broadcast or nameserver.
int
default:"TYPE_WORKSTATION"
NetBIOS name type
str
NetBIOS scope
int
default:"1"
Query timeout in seconds
list[NODE_NAME_ENTRY]
List of NetBIOS name entries registered by the node

getnetbiosname()

Get the NetBIOS name for an IP address.
str
required
IP address to query
str
NetBIOS name of the server type (0x20)

getmacaddress()

Get MAC address from last node status query.
str
MAC address in format 'AA-BB-CC-DD-EE-FF'

set_nameserver()

Set a specific NetBIOS nameserver.
str
required
IP address of NetBIOS nameserver

set_broadcastaddr()

Set the broadcast address for queries.
str
required
Broadcast address

NetBIOSTCPSession

TCP-based NetBIOS session for SMB communication.
str
required
Local NetBIOS name
str
required
Remote NetBIOS name
str
required
Remote IP address
int
default:"TYPE_SERVER"
Remote NetBIOS name type
int
default:"139"
Session port (139 for NetBIOS, 445 for direct SMB)
int
Connection timeout

send_packet()

Send a NetBIOS session packet.
bytes
required
Data to send

recv_packet()

Receive a NetBIOS session packet.
int
Receive timeout in seconds
NetBIOSSessionPacket
Received packet

NetBIOSUDPSession

UDP-based NetBIOS datagram service.

Constants

Port Numbers

Name Types

Node Types

Supporting Classes

NODE_NAME_ENTRY

Represents a NetBIOS name entry from node status.
bytes
NetBIOS name (15 bytes)
int
Name type suffix (0x00, 0x20, etc.)
int
Name flags (active, permanent, conflict, etc.)

NBPositiveNameQueryResponse

Response from name query containing IP addresses.
list[str]
List of IP addresses

NetBIOSSessionPacket

Represents a NetBIOS session packet.
int
Packet type (MESSAGE, REQUEST, RESPONSE, etc.)
bytes
Packet data payload
int
Payload length

Exceptions

NetBIOSError

Raised when NetBIOS operations fail.

NetBIOSTimeout

Raised when operations timeout.

Usage Examples

Name Resolution

Node Status Query

Get NetBIOS Name from IP

Network Scanning

Using with SMB

Enumerating Domain Controllers

Custom NetBIOS Session

Helper Functions

encode_name()

Encode a NetBIOS name.
str
required
NetBIOS name (max 15 characters)
int
required
Name type suffix
str
NetBIOS scope
bytes
Encoded NetBIOS name

decode_name()

Decode an encoded NetBIOS name.
bytes
required
Encoded name data
int
Bytes consumed
str
Decoded name
str
Scope identifier

See Also