title: How can I find the IP address of a host using mdns?
body: <p>My target is to discover the IP address of a Linux computer &quot;server&quot; in the local network from a Windows computer. From another Linux computer &quot;client&quot; I can do:</p>
  <pre><code>ping -c1 server.local
  </code></pre>
  <p>and get a reply. Both &quot;server&quot; and &quot;client&quot; run Avahi, so this is easy. However, I would like to discover the IP address of &quot;server&quot; from a Python application of mine, which runs on both MS Windows and Linux computers. Note: on MS Windows computers that <strong>do not</strong> run mDNS software, there is no hostname resolution (and obviously <code>ping</code> does not work on said Windows systems).</p>
  <p>I know of the existence of <a href="http://sourceforge.net/projects/pyzeroconf" rel="noreferrer">pyzeroconf</a>, and this is the module I tried to use; however, the documentation is scarce and not very helpful to me. Using tools like <code>avahi-discover</code>, I figured that computers publish records of the service type <code>_workstation._tcp.local.</code> (with the obviously dummy port 9, the discard service) of mDNS type <code>PTR</code> that might be the equivalent of a DNS A record. Or I might have misunderstood completely the mDNS mechanism.</p>
  <p>How can I discover the IP address of a computer (or get a list of IP addresses of computers) through mDNS from Python?</p>
  <h3>CLARIFICATION (based on a comment)</h3>
  <p>The obvious <code>socket.gethostbyname</code> works on a computer running and configured to use mDNS software (like Avahi):</p>
  <pre><code>Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
  [GCC 4.4.3] on linux2
  Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
  &gt;&gt;&gt; import socket
  &gt;&gt;&gt; socket.gethostbyname('server.local')
  '192.168.42.42'
  </code></pre>
  <p>However, on Windows computers not running mDNS software (the default), I get:</p>
  <pre><code>Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
  Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
  &gt;&gt;&gt; import socket
  &gt;&gt;&gt; socket.gethostbyname('server.local')
  Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  socket.gaierror: [Errno 11001] getaddrinfo failed
  </code></pre>