C# 取得本機IP
C# 取得本機(本地端) IP
資料來源: https://johnnyjong823.pixnet.net/blog/post/176530150-c%23–%E8%AE%80%E5%8F%96%E6%9C%AC%E6%A9%9Fip%E4%BD%8D%E7%BD%AE
code:
using System.Net;//記得先import
static void Main(string[] args)
{
String strHostName = Dns.GetHostName();//先讀取本機名稱
IPHostEntry iphostentry = Dns.GetHostByName(strHostName); //取得本機的 IpHostEntry 類別實體
string ip="";
foreach (IPAddress ipaddress in iphostentry.AddressList)
{
Console.WriteLine(ipaddress.ToString());//使用了兩種方式都可以讀取出IP位置
}
Console.WriteLine(ip);
Console.ReadLine();
}
One thought on “C# 取得本機IP”
C# 取得本機(本地端) LOCAL IP