标签:
* 在使用前,一定要注意在头部加上引用:
using System.Net;
代码如下:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Net; 5 using System.Text; 6 7 namespace ConsoleApplication1 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 Console.Write(new Program().GetHostInfo()); 14 Console.ReadLine(); 15 } 16 //获取本地IP等信息 17 protected string GetHostInfo() 18 { 19 StringBuilder Info = new StringBuilder(""); 20 IPAddress[] ipHost = Dns.GetHostAddresses(Dns.GetHostName()); 21 Info.Append("本机名:"); 22 Info.Append(Dns.GetHostName()); 23 Info.Append(" -> "); 24 Info.Append("IP 地址:"); 25 Info.Append(" -> "); 26 foreach (IPAddress address in ipHost) 27 { 28 Info.Append(address.ToString()); 29 Info.Append(" >> "); 30 } 31 return Info.ToString(); 32 } 33 } 34 }
标签:
原文地址:http://www.cnblogs.com/willingtolove/p/4607381.html