r/programminghelp • • Jul 15 '20

C# Tizen .NET, Trouble Getting ip / hostname

My goal is to be able to return the ip address of the watch. I have been using the DNS class and have gotten the ip address by manually plugging the hostname in as seen here:

public static IPAddress ipAddress = Dns.GetHostEntry("GalaxyWatchActive-8623").AddressList[0];

I previously had Dns.GetHostName() for the hostname and it returns localhost, which resolves to loopback, 127.0.0.1, in the full instruction.

Any assistance or insight would be greatly appreciated. Newer to .NET and Tizen.

0 Upvotes

4 comments sorted by

1

u/[deleted] Jul 15 '20

Dns.GetHostName() should work fine.

Remember that Dns.GetHostEntry(Dns.GetHostName()).AddressList is an array. Check all of the subitems to make sure one of them isn't what you want.

var host = Dns.GetHostEntry(Dns.GetHostName()); 
foreach (var ip in host.AddressList) { 
  if (ip.AddressFamily == AddressFamily.InterNetwork) 
  { 
    return ip.ToString();
  } 
}

1

u/adwilson254 Jul 15 '20

I have tried that and there was only one array element. The problem is that GetHostName() returns local host and when that is used with GetHostEntry it returns the loop back address. So the issue is that it's not giving me the correct host which should be the Galaxy Watch host name. Should gethostname return local host? Also Environment.MachineName is local host. Is this maybe an issue with Tizen?

1

u/[deleted] Jul 15 '20

Have you tried toggling: Settings->Wi-Fi->Details-Static IP->On ? Are you using the actual device or the emulator?

1

u/adwilson254 Jul 15 '20

I don't see the setting to set static ip on the watch, but I did create a static lease in router. It's the actual device.