CodePanic! > C#.NET Tips > 今ここ■ホスト名からIPアドレスを取得するホスト名からIPアドレスを取得するには System.Net.DnsクラスのGetHostEntry関数を使います。
// IPを調べたいホスト名
string hostname = "www.yahoo.co.jp";
// IPHostEntry取得
System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(hostname);
// 最初のアドレスを取得
System.Net.IPAddress ip = hostEntry.AddressList[0];
// xxx.xxx.xxx.xxx形式の文字列を取得
string IPaddress = ip.ToString();
|