<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NBNSProtocol Class — pysmb 1.2.7 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="NetBIOS class" href="nmb_NetBIOS.html" />
<link rel="prev" title="Welcome to pysmb’s documentation!" href="../index.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="nmb_NetBIOS.html" title="NetBIOS class"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="../index.html" title="Welcome to pysmb’s documentation!"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.7 documentation</a> »</li>
<li class="nav-item nav-item-this"><a href="">NBNSProtocol Class</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="nbnsprotocol-class">
<h1>NBNSProtocol Class<a class="headerlink" href="#nbnsprotocol-class" title="Permalink to this headline">¶</a></h1>
<p>pysmb has a <em>NBNSProtocol</em> implementation for Twisted framework.
This allows you to perform name query asynchronously without having your application to block and wait for the results.</p>
<dl class="simple">
<dt>In your project,</dt><dd><ol class="arabic simple">
<li><p>Create a NBNSProtocol instance.</p></li>
<li><p>Just call <em>queryName</em> method which will return a <em>Deferred</em> instance. Add your callback function to the <em>Deferred</em> instance via <em>addCallback</em> method to receive the results of the name query.</p></li>
<li><p>When you are done with the NBNSProtocol instance, call its <NBNSProtocol instance>.transport.stopListening method to remove this instance from the reactor.</p></li>
</ol>
</dd>
</dl>
<dl class="py class">
<dt id="nmb.NetBIOSProtocol.NBNSProtocol">
<em class="property">class </em><code class="sig-prename descclassname">nmb.NetBIOSProtocol.</code><code class="sig-name descname">NBNSProtocol</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">broadcast</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">listen_port</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol" title="Permalink to this definition">¶</a></dt>
<dd><dl class="py method">
<dt id="nmb.NetBIOSProtocol.NBNSProtocol.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">broadcast</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">listen_port</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Instantiate a NBNSProtocol instance.</p>
<p>This automatically calls reactor.listenUDP method to start listening for incoming packets, so you <strong>must not</strong> call the listenUDP method again.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>broadcast</strong> (<em>boolean</em>) – A boolean flag to indicate if we should setup the listening UDP port in broadcast mode</p></li>
<li><p><strong>listen_port</strong> (<em>integer</em>) – Specifies the UDP port number to bind to for listening. If zero, OS will automatically select a free port number.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="nmb.NetBIOSProtocol.NBNSProtocol.datagramReceived">
<code class="sig-name descname">datagramReceived</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">data</span></em>, <em class="sig-param"><span class="n">from_info</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol.datagramReceived"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol.datagramReceived" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when a datagram is received.</p>
<p>@param datagram: the string received from the transport.
@param addr: tuple of source of datagram.</p>
</dd></dl>
<dl class="py method">
<dt id="nmb.NetBIOSProtocol.NBNSProtocol.queryIPForName">
<code class="sig-name descname">queryIPForName</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">ip</span></em>, <em class="sig-param"><span class="n">port</span><span class="o">=</span><span class="default_value">137</span></em>, <em class="sig-param"><span class="n">timeout</span><span class="o">=</span><span class="default_value">30</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol.queryIPForName"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol.queryIPForName" title="Permalink to this definition">¶</a></dt>
<dd><p>Send a query to the machine with <em>ip</em> and hopes that the machine will reply back with its name.</p>
<p>The implementation of this function is contributed by Jason Anderson.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>ip</strong> (<em>string</em>) – 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.</p></li>
<li><p><strong>port</strong> (<em>integer</em>) – 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.</p></li>
<li><p><strong>timeout</strong> (<em>integer/float</em>) – Number of seconds to wait for a reply, after which the method will return None</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A <em>twisted.internet.defer.Deferred</em> instance. The callback function will be called with a list of names of the machine at <em>ip</em>.
On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="nmb.NetBIOSProtocol.NBNSProtocol.queryName">
<code class="sig-name descname">queryName</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="n">ip</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">port</span><span class="o">=</span><span class="default_value">137</span></em>, <em class="sig-param"><span class="n">timeout</span><span class="o">=</span><span class="default_value">30</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol.queryName"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol.queryName" title="Permalink to this definition">¶</a></dt>
<dd><p>Send a query on the network and hopes that if machine matching the <em>name</em> will reply with its IP address.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>ip</strong> (<em>string</em>) – 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.</p></li>
<li><p><strong>port</strong> (<em>integer</em>) – 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.</p></li>
<li><p><strong>timeout</strong> (<em>integer/float</em>) – Number of seconds to wait for a reply, after which the returned Deferred instance will be called with a NetBIOSTimeout exception.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A <em>twisted.internet.defer.Deferred</em> 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</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="nmb.NetBIOSProtocol.NBNSProtocol.stopProtocol">
<code class="sig-name descname">stopProtocol</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NBNSProtocol.stopProtocol"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NBNSProtocol.stopProtocol" title="Permalink to this definition">¶</a></dt>
<dd><p>Called when the transport is disconnected.</p>
<p>Will only be called once, after all ports are disconnected.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="nmb.NetBIOSProtocol.NetBIOSTimeout">
<em class="property">class </em><code class="sig-prename descclassname">nmb.NetBIOSProtocol.</code><code class="sig-name descname">NetBIOSTimeout</code><a class="reference internal" href="../_modules/nmb/NetBIOSProtocol.html#NetBIOSTimeout"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#nmb.NetBIOSProtocol.NetBIOSTimeout" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised in NBNSProtocol via Deferred.errback method when queryName method has timeout waiting for reply</p>
</dd></dl>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="../index.html"
title="previous chapter">Welcome to pysmb’s documentation!</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="nmb_NetBIOS.html"
title="next chapter">NetBIOS class</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/api/nmb_NBNSProtocol.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="nmb_NetBIOS.html" title="NetBIOS class"
>next</a> |</li>
<li class="right" >
<a href="../index.html" title="Welcome to pysmb’s documentation!"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">pysmb 1.2.7 documentation</a> »</li>
<li class="nav-item nav-item-this"><a href="">NBNSProtocol Class</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2001-2021, Michael Teo https://miketeo.net/.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.4.3.
</div>
</body>
</html>