检查静态或动态的IP地址在C#.NET? [英] Checking static or dynamic IP address in C# .NET?

查看:147
本文介绍了检查静态或动态的IP地址在C#.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个pretty的基本形式的应用程序。

I am building a pretty basic form app.

我可以得到IP地址可用的本地计算机上的列表。不过,我想还需要确定这些地址获得(如DHCP或静态)。我怎样才能知道,如果一个静态IP地址,在系统中配置?

I can get a list of IP addresses available on the local machine. However, I want to also determine how these addresses are obtained (e.g. DHCP or static). How can I tell if a static IP address is configured on the system?

我们的目标是要告知新手最终用户(谁可能不知道网络设置,或如何获得它的)什么的静态IP地址可用。而且,如果没有静态地址存在,告诉他们一个需要进行设置。

The goal is to inform a novice end-user (who may have no knowledge of the network setup, or how to obtain it) what static IP addresses are available. And, if no static address exist, inform them that one needs to be setup.

TIA

推荐答案

不幸的是,你可能不得不使用WMI。有可能是另一种方式,但是这是我知道的唯一途径。

Unfortunately you'll probably have to use WMI. There might be another way, but this is the only way that I know.

这code将输出的所有有关系统上的每个适配器的信息。我觉得这个名字是DHCPEnabled相你想要的属性。

This code will output all of the information about every adapter on your system. I think the name is "DHCPEnabled" of the property you want.

        ManagementObjectSearcher searcherNetwork =
        new ManagementObjectSearcher("root\\CIMV2",
        "SELECT * FROM Win32_NetworkAdapterConfiguration");

        foreach (ManagementObject queryObj in searcherNetwork.Get())
        {
            foreach (var prop in queryObj.Properties)
            {
                Console.WriteLine(string.Format("Name: {0} Value: {1}", prop.Name, prop.Value));
            }
        }

这篇关于检查静态或动态的IP地址在C#.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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