简体   繁体   中英

How to resolve the host / machine name with an IP address on windows phone

Anyone know if it can recover the ( hostname/machine name ) with a local IP address ? I know that the resolution reverse 'hostname -> ip' works perfectly with DeviceNetworkInformation.ResolveHostNameAsync (endpoint, OnNameResolved, null).

Is it possible to do the same thing but in reverse? Given the IP of a Local Machine and retrieve its hostname? A thousand thanks

Here is my code , but it's doesn't work the host is always called "192.168.1.5" like the ip . And it's should return "computer0001"

DeviceNetworkInformation.ResolveHostNameAsync("192.168.1.5", OnNameResolved, null);

private void OnNameResolved(NameResolutionResult result)
{
     IPEndPoint[] endpoints = result.IPEndPoints;
     if (endpoints != null)
     {
         if (endpoints.Length > 0)
         {
             //Host always return ip adress and not the machine name
             host = endpoints[0].ToString();
         }
     }
 }

Not sure if there is specific API on Windows Phone for that purpose.

I suggest you looking into similar question 'DNS lookup from custom DNS server in c#' .

If you're okay with going only WP8, then you should study this part of MSDN - Supported Win32 APIs for Windows Phone 8 .

For example, getpeername function might return you information you're looking for. Or you might create new HostName object passing IP address there and trying to read DisplayName, CanonicalName or RawName properties of it.

Make sure you test with both emulator and real device as WP8 emulator has a little bit complex network configuration.

Would be great if you can update us if you have any success with the task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM