Share via


方法 : Smartphone エミュレータの IP アドレスを表示する

更新 : 2007 年 11 月

Smartphone エミュレータの IP アドレスを探索するには、プログラムによる方法が必要です。このようなルーチンを作成して実行する手順を次に示します。

ルーチンを作成するには

  1. Visual Studio で、C# Smartphone の新しい空のプロジェクトを開きます。

  2. ソリューション エクスプローラで、プロジェクトを右クリックし、[追加] をポイントして、[新しい項目] をクリックします。

  3. [コード ファイル] をクリックし、[追加] をクリックします。

    コード エディタが開き、空白のページが表示されます。

  4. 次のコード ブロックをエディタのページにコピーします。

    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. ソリューション エクスプローラで、[参照設定] を右クリックし、[参照の追加] をクリックします。

  6. [System.Windows.Forms] をクリックし、[OK] をクリックします。

ルーチンを実行するには

  1. [デバッグ] メニューの [デバッグ開始] をクリックします。

  2. [配置] ダイアログ ボックスで、IP アドレスを表示する Smartphone エミュレータをクリックします。

  3. [配置] をクリックします。

    アプリケーションで IP アドレスが表示されます。

参照

処理手順

接続のトラブルシューティング

その他の技術情報

デバイス エミュレータの構成と使用