Dns.GetHostEntry()

First to mention. Yesterday, I got my IP with the latest firmware and the On Board Ethernet SC20260. Today, I try again (just restarted VS and no changes since yesterday and got no IP again
But I have another question. I want to get the IP address of my PC directly from the SC20260. I use the Dns.GetHostEntry but I have a InvalidOperationException.
while it works fine on any pc connected on the network

Actually, are you sure you can get that entry out of DNS? Use NSLOOKUP to confirm. I suspect other PCs in the local network are discovering it NOT through DNS but some broadcast/ARP process.

well, If I call Dns.GetHostEntry from a winform app (C#) , I can get the IP address of all devices connected on my home network as long as they have a name. I can get the IP from the router, a HP printer, a Nas and my company pc.

Sure. But is it really coming from DNS? Do the NSLOOKUP test for me for giggles.

Well, network is not my specialty at all but how could NSLOOKUP find an IP address that is behind my router ?

I don‘t know why, but others reported before for NETMF: put the command in a try/catch block and perform it two times.

I tried 40 times and got 40 times

exactly my point. A true DNS lookup will not find your local machines unless they are actually registering into a local DNS as well (if you’re at work, there’s a chance that this IS happening, but unlikely at home)

Ignore the catch
IpAddress[] address = null;
try
{
address = Dns.GetHostEntry(…).AddressList;
}
catch
{}
and the Same one more time

My team is based in Chicago and I am working from home (Belgium). I never made any modification on my router. so it may be unusual but it is still detected by the winform app. i also have a program called ip scanner pro and the name appears as well in the list. this is the reason why i was expecting to get it from Tinyclr as well. (note that it doesn’t for devices connected by wifi)

Did you try to set your routers Gateway Address as the first DNS resolver?

networkInterfaceSetting.Address = new IPAddress(new byte[] { 192, 168, 1, 122 });
        networkInterfaceSetting.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 });
        networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 });           
        networkInterfaceSetting.DnsAddresses = new IPAddress[] { new IPAddress(new byte[]
    { 192, 168, 1, 1 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };

I am out for the week end but I will try this on Monday. Good idea

I tried but no changes. i may try using a ddns like changeip, duckdns…

probably not going to change your outcome.

Honestly, what the PC does is beyond what I expect a DNS query to do. If you use NSLOOKUP as the basis for doing an actual DNS query, that’s the results that you should expect. The reason a PC does so much more is that the networking stack is immense, and it’s giving you results not just from a DNS query, it’s doing local name resolution (a-la netbios names).

When I get time I’ll do a test with my home router that can link DHCP and DNS so that a DNS query to the router will return the local names. But even then that’s not strictly the same as a Windows PC will do…

i belive it can resolved by adding entry at router for DNS (same ip as gateway) as @RoSchmi said above and it can be able to query by name similiar to PC (not tested because i am on terrain) with DHCP enabled too.

an little video

agree, basically if the router’s DHCP server can add it to a local DNS then DNS query will resolve it. The PC is doing waaaaaay more than just a DNS query to get that answer.

For me Dns.GetHostEntry() successfully resolves the IP-Address of my PC in the Network if I set the first of the networkInterfaceSetting.DnsAddresses to my Gateway IP-Address (for me: 192.168.1.1). If I leave networkInterfaceSetting.DnsAddresses as they are in the GHI example, the IP Address of my PC is not resolved (is null). I’m using the ENC28 Ethernet module.
I would now look in the Web Interface of your router with which name your PC appears there. Then I would set a breakpoint in the line: while (linkReady == false) an look in the networkController which Dns Server IPAddresses are effectively used.
Then (I don’t know if it is really important) I would use a PC-Name with not more than 8 characters and without space characters in the name.

thanks For the tip. but i did checked this already and value reported by ipconfig match the ones in the router settings

yes, unfortunately, a pc does more that Tinyclr in this case. i first plan to have tinyclr boards sending data to my home pc or small pc like latte panda. ok as long as the pc ip adress doesn’t change but would like to have to capability to retrieve ip simply by using the name. thanks for all your inputs

look at your router then, and see if it will do DHCP/DNS, or look for one that does… there’s a whole protocol field in name discovery :slight_smile: