NetBIOS class¶
- To use the NetBIOS class in your application,
- Create a new NetBIOS instance
- 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.
- When you are done, call close method to release the underlying resources.
-
class
nmb.NetBIOS.
NetBIOS
(broadcast=True, listen_port=0)¶ -
__init__
(broadcast=True, listen_port=0)¶ 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
()¶ 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)¶ 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)¶ 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.
-