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

  1. In Visual Studio, open a new, empty C# Smartphone project.

  2. In Solution Explorer, right-click the project, point to Add, and then click New Item.

  3. Click Code File, and then click Add.

    The code editor opens with a blank page.

  4. 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");
            }
        }
    }
    
  5. In Solution Explorer, right-click References, and then click Add Reference.

  6. Click System.Windows.Forms, and then click OK.

To run the routine

  1. On the Debug menu, click Start Debugging.

  2. In the Deploy dialog box, click the Smartphone emulator whose IP addresses you want to display.

  3. Click Deploy.

    The application displays the IP addresses.

See Also

Tasks

Troubleshooting Connection Issues

Other Resources

Configuring and Using the Device Emulator