本文介绍了如何以编程方式获取计算机的本地IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用C#和.NET 3.5从我的程序中获取计算机的实际本地网络IP地址(例如192.168.0.220)。在这种情况下,我不能只使用127.0.0.1。
I need to get the actual local network IP address of the computer (e.g. 192.168.0.220) from my program using C# and .NET 3.5. I can't just use 127.0.0.1 in this case.
执行此操作的最佳方法是什么?
What's the best way to do this?
推荐答案链接 它说在那里,添加System,并使用以下
Link It says there, add System, and using the following
//To get the local IP address string sHostName = Dns.GetHostName (); IPHostEntry ipE = Dns.GetHostByName (sHostName); IPAddress [] IpA = ipE.AddressList; for (int i = 0; i < IpA.Length; i++) { Console.WriteLine ("IP Address {0}: {1} ", i, IpA[i].ToString ()); }更多推荐
如何以编程方式获取计算机的本地IP地址?
发布评论