# NBNSProtocol Class

pysmb has a NBNSProtocol implementation for Twisted framework. This allows you to perform name query asynchronously without having your application to block and wait for the results.

In your project,
  1. Create a NBNSProtocol instance.
  2. Just call queryName method which will return a Deferred instance. Add your callback function to the Deferred instance via addCallback method to receive the results of the name query.
  3. When you are done with the NBNSProtocol instance, call its <NBNSProtocol instance>.transport.stopListening method to remove this instance from the reactor.

class `nmb.NetBIOSProtocol.``NBNSProtocol`(broadcast=True, listen_port=0)
  `__init__`(broadcast=True, listen_port=0)

    Instantiate a NBNSProtocol instance.

    This automatically calls reactor.listenUDP method to start listening for incoming packets, so you must not call the listenUDP method again.

    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.

  `queryIPForName`(ip, port=137, timeout=30)

    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 twisted.internet.defer.Deferred instance. The callback function will be called with a list of names of the machine at ip. On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception

  `queryName`(name, ip='', port=137, timeout=30)

    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 returned Deferred instance will be called with a NetBIOSTimeout exception.
    Returns: | A twisted.internet.defer.Deferred instance. The callback function will be called with a list of IP addresses in dotted notation (aaa.bbb.ccc.ddd). On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception

class `nmb.NetBIOSProtocol.``NetBIOSTimeout`

  Raised in NBNSProtocol via Deferred.errback method when queryName method has timeout waiting for reply