0
0

【C#】ホスト名からIPアドレスを知りたい

Last updated at Posted at 2022-08-14

この記事は移転します

ホスト名からIPアドレスを調べたい

using System.Net;

//解決したいホスト名
string HostName = "ホスト名";

//IPHostEntryオブジェクトを取得
IPHostEntry iphe = Dns.GetHostEntry(HostName);

//IPアドレスのリストを取得
IPAddress[] adList = iphe.AddressList;

//IPアドレスを列挙
for (int ip_cnt = 0; ip_cnt < adList.Length; ip_cnt++)
{
  string LocalIpAddress = adList[ip_cnt].ToString();
  Console.WriteLine(LocalIpAddress);
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0