How to: Display IP Addresses for Smartphone Emulators
Discovering IP addresses for Smartphone emulators requires a programmatic approach. The following steps illustrate how to create and run one such routine.
To create the routine
In Visual Studio, open a new, empty C# Smartphone project.
In Solution Explorer, right-click the project, point to Add, and then click New Item.
Click Code File, and then click Add.
The code editor opens with a blank page.
Copy the following code block onto the editor page.
using System; using System.Net; using System.Text; using System.Windows.Forms; public class GetAddress { /// <summary> /// A sample application that displays a list of IP addresses /// that are bound to the current device. /// </summary> static void Main() { try { IPHostEntry IPHost = Dns.Resolve(Dns.GetHostName()); IPAddress[] addressList = IPHost.AddressList; if (addressList.Length > 0) { StringBuilder address = new StringBuilder(); foreach (IPAddress a in addressList) { address.Append(a.ToString()); address.Append(" "); } MessageBox.Show(address.ToString(), "IP Addresses"); } else MessageBox.Show("Unable to determine network address", "Error"); } catch (Exception) { MessageBox.Show("Unable to determine network address", "Error"); } } }
In Solution Explorer, right-click References, and then click Add Reference.
Click System.Windows.Forms, and then click OK.
To run the routine
On the Debug menu, click Start Debugging.
In the Deploy dialog box, click the Smartphone emulator whose IP addresses you want to display.
Click Deploy.
The application displays the IP addresses.
See Also
Tasks
Troubleshooting Connection Issues