This will return an array of IP Address objects, and you can use the Address property of the IP Address object to get the IP address as a string.
Write this code on your class file :
using System;using System.Net;
IPAddress[] addresses = Dns.GetHostAddresses("iphone-wi.local");
foreach (IPAddress address in addresses)
{
Console.WriteLine("IP Address: " + address.ToString());
}
This will only work if the iPhone is connected to the same Wi-Fi network as the computer running the C# code.
You can also use the same approach for the cellular network by replacing "iphone-wi.local" with "iphone-cell.local" Keep in mind that this method may not work if the iPhone has a private IP address assigned by a cellular network or if the reverse DNS lookup fails.
Comments
Post a Comment