如何以编程方式获取计算机的本地IP地址?

编程入门 行业动态 更新时间:2024-10-28 07:30:47
本文介绍了如何以编程方式获取计算机的本地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地址?

本文发布于:2023-05-25 10:50:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   地址   计算机   IP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!