我怎样才能获得本地机器? [英] How Could I Get Local Machine Ip ?

查看:74
本文介绍了我怎样才能获得本地机器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用C#捕获并存储我的本地系统IP?



我该怎么办?

i have to catch and store my local system IP using C# ?

how could i do ?

推荐答案

您是否尝试使用 Google [ ^ ]?



您可以使用 GetHostAddresses [ ^ ]



这样的事情开始会很好:



Did you try to use Google[^]?

You can make use of GetHostAddresses [^]

Something like this would be good to start with:

IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress addr in localIPs)
{
    Console.WriteLine(addr);
}


http://stackoverflow.com/questions/8709427/get-local-system-ip-address-using-c-sharp [ ^ ]



这将起作用
http://stackoverflow.com/questions/8709427/get-local-system-ip-address-using-c-sharp[^]

This will work


{
            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (IPAddress addr in localIPs)
                             
            {
              //  Console.WriteLine(addr);
                Console.Write(localIPs[1]);
            }

        }










Here the solution if configuration have more than one IP


这篇关于我怎样才能获得本地机器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆