首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

多个网卡 设立IP C

2012-09-10 
多个网卡设置IPC#下面代码是“C# 设置IP”的实例代码。需求是:当前机器安装有几个网卡,想通过程序设置其中一

多个网卡 设置IP C#
下面代码是“C# 设置IP”的实例代码。
需求是:

当前机器安装有几个网卡,想通过程序设置其中一个网卡的局域网IP地址,怎么实现?

C# code
1、在 “解决方案资源管理器” 右击 “引用” 添加 “System.Management” 的引用。2、添加 “using System.Management;”。         static void SetNetworkAdapter()        {            ManagementBaseObject inPar = null;            ManagementBaseObject outPar = null;            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");            ManagementObjectCollection moc = mc.GetInstances();            foreach (ManagementObject mo in moc)            {                if (!(bool)mo["IPEnabled"])                    continue;                //设置ip地址和子网掩码                 inPar = mo.GetMethodParameters("EnableStatic");                inPar["IPAddress"] = new string[] { "192.168.16.248", "192.168.16.249" };// 1.备用 2.IP                inPar["SubnetMask"] = new string[] { "255.255.255.0", "255.255.255.0" };                outPar = mo.InvokeMethod("EnableStatic", inPar, null);                //设置网关地址                 inPar = mo.GetMethodParameters("SetGateways");                inPar["DefaultIPGateway"] = new string[] { "192.168.16.2", "192.168.16.254" }; // 1.网关;2.备用网关                outPar = mo.InvokeMethod("SetGateways", inPar, null);                //设置DNS                 inPar = mo.GetMethodParameters("SetDNSServerSearchOrder");                inPar["DNSServerSearchOrder"] = new string[] { "211.97.168.129", "202.102.152.3" }; // 1.DNS 2.备用DNS                outPar = mo.InvokeMethod("SetDNSServerSearchOrder", inPar, null);                break;            }        }


[解决办法]
帮顶。不会
[解决办法]
http://www.codeproject.com/KB/cs/Chameleon.aspx

热点排行