<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Search IP address in DHCP local network]]></title><description><![CDATA[<p dir="auto">Hello everybody</p>
<p dir="auto">I need to connect via QTcpSocket to a server in my local network. Such server has a dynamic IP assigned by the DHCP. Therefore, I don't know the IP address, but I know its hostname.</p>
<p dir="auto">However, if i use the example code in the QHostInfo Class documentation as follows</p>
<pre><code>QHostInfo::lookupHost("myServerHostName", this, SLOT(lookedUp(QHostInfo)));
</code></pre>
<pre><code>void MainWindow::lookedUp(const QHostInfo &amp;host)
{
    if (host.error() != QHostInfo::NoError) {
            qDebug() &lt;&lt; "Lookup failed:" &lt;&lt; host.errorString();
            return;
        }

        qDebug() &lt;&lt; "Found HOST: " &lt;&lt; host.hostName();
        const auto addresses = host.addresses();
        for (const QHostAddress &amp;address : addresses)
            qDebug() &lt;&lt; "Found address:" &lt;&lt; address.toString();
}
</code></pre>
<p dir="auto">it will return <strong>Lookup failed: "Host not found"</strong><br />
If instead I use</p>
<pre><code>QHostInfo::lookupHost("192.168.etc.", this, SLOT(lookedUp(QHostInfo)));
</code></pre>
<p dir="auto">It will successfully find the server I need to connect to, but this can't be my solution since in the final release of my application I won't be able to know such IP address a priori.</p>
<p dir="auto">One possible solution would be to use a brute force approach for every possible IP address, but it would be way too slow.<br />
Another solution could be to try to get all IP addresses on the LAN (maybe by interrogating the DHCP server). Then I would brute force on a much smaller number of addresses and it would be fast enough, but I don't know hot to do it and <a href="https://forum.qt.io/topic/12658/how-to-get-all-ip-address-on-a-lan">HERE</a> they say it is not a reliable way and do not give a solution to the question.<br />
I could try to ping a broadcast and try to use QHostInfo::lookupHost on everyone that answers to my ping, but I do not know how to do it either.</p>
<p dir="auto">Can anyone help me to solve this problem?</p>
<p dir="auto">ps: I needs to work regardless the operative system (windows/linux/macos).</p>
]]></description><link>https://forum.qt.io/topic/100758/search-ip-address-in-dhcp-local-network</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Nov 2026 05:51:05 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/100758.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 15 Mar 2019 11:10:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Search IP address in DHCP local network on Fri, 15 Mar 2019 12:18:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/davide87">@<bdi>Davide87</bdi></a> said in <a href="/post/517675">Search IP address in DHCP local network</a>:</p>
<blockquote>
<p dir="auto">Such server has a dynamic IP assigned by the DHCP. Therefore, I don't know the IP address, but I know its hostname.</p>
</blockquote>
<p dir="auto">It looks like your problem is about networking, not Qt-related.</p>
<p dir="auto">You need to ensure your network provides a good way for name resolution (i.e. DNS service).  If your server is assigned a dynamic IP via DHCP that a DNS entry for such server name is keep up to date. This <a href="https://www.semicomplete.com/articles/dynamic-dns-with-dhcp/" target="_blank" rel="noopener noreferrer nofollow ugc">post</a> could be a potential guide just in case.</p>
]]></description><link>https://forum.qt.io/post/517691</link><guid isPermaLink="true">https://forum.qt.io/post/517691</guid><dc:creator><![CDATA[Pablo J. Rogina]]></dc:creator><pubDate>Fri, 15 Mar 2019 12:18:58 GMT</pubDate></item></channel></rss>