Search code examples
c#dnsresolvedynamic-ipnoip

Resolve IP from No-IP DNS A


I need to Resolve the IP from my No-IP Hostname, which I setup because I'm behind a Router and this Router doesn't have a static public IP. The hostname is setup as a DNS A record. I need the IP to reverse connect from a computer to my own pc.

I already tried it with:

IPAddress address = Dns.GetHostAddresses("****.ddns.net")[0];

But that only writes "127.0.0.1" to "address".

Can someone help me?


Solution

  • I think, the problem is, that "****.ddns.net" is not a resolvable IP adress. In my example i use "heise.de" and it works fine.

    What GetHostAddresses does is, asking the name service of your computer if it knows that concrete name. And if it doesn't know itself, it will ask its parent, and so on. If somebody knows the name, it will give that ip to you. But for that to work, you have to ask for a concrete resolvable name.

    Also, you should check, if the returned list is empty:

            System.Net.IPAddress[] adresses = System.Net.Dns.GetHostAddresses("heise.de");
            if (adresses.Length > 0)
            {
                System.Net.IPAddress address = System.Net.Dns.GetHostAddresses("heise.de")[0];
            }
    

    It look's like you are using DynDNS, so the name you are looking for should be well known. If you don't get the correct ip for it, then there is something wrong with the setup of your dns system.