[C#]获取本地IP
  • 分类:C#
  • 发表:2017-10-02
  • 围观(114)
  • 评论(0)

首先呢,先导入包,之后直接用一个标签直接显示出来就行了,大概的操作流程就是下面:

using System.NET;
string AddressIP = string.Empty;
            foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
            {
                if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
                {
                    AddressIP = _IPAddress.ToString();
                }
            }
            Label1.Text = AddressIP;

 

共有 0 条评论

Top