Previous topic

NBNSProtocol Class

Next topic

SMBConnection Class

This Page

NetBIOS class

To use the NetBIOS class in your application,
  1. Create a new NetBIOS instance
  2. Call queryName method for each name you wish to query. The method will block until a reply is received from the remote SMB/CIFS service, or until timeout.
  3. When you are done, call close method to release the underlying resources.
class nmb.NetBIOS.NetBIOS(broadcast=True, listen_port=0)[source]
__init__(broadcast=True, listen_port=0)[source]

Instantiate a NetBIOS instance, and creates a IPv4 UDP socket to listen/send NBNS packets.

Parameters:
  • broadcast (boolean) – A boolean flag to indicate if we should setup the listening UDP port in broadcast mode
  • listen_port (integer) – Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.
close()[source]

Close the underlying and free resources.

The NetBIOS instance should not be used to perform any operations after this method returns.

Returns:None
queryIPForName(ip, port=137, timeout=30)[source]

Send a query to the machine with ip and hopes that the machine will reply back with its name.

The implementation of this function is contributed by Jason Anderson.

Parameters:
  • ip (string) – If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address. If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
  • port (integer) – The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
  • timeout (integer/float) – Number of seconds to wait for a reply, after which the method will return None
Returns:

A list of string containing the names of the machine at ip. On timeout, returns None.

queryName(name, ip='', port=137, timeout=30)[source]

Send a query on the network and hopes that if machine matching the name will reply with its IP address.

Parameters:
  • ip (string) – If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address. If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query.
  • port (integer) – The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing.
  • timeout (integer/float) – Number of seconds to wait for a reply, after which the method will return None
Returns:

A list of IP addresses in dotted notation (aaa.bbb.ccc.ddd). On timeout, returns None.