C#实现更改IP功能源码 - greystar的专栏 - CSDNBlog
using System;
using System.Management;
public class ChangeIP
{
private ManagementBaseObject iObj = null;
private ManagementBaseObject oObj = null;
private ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
private readonly ManagementObjectCollection moc;
///
/// example:
///
/// ChangeIP o = new ChangeIP();
/// string[] ipList = new string[]{"192.168.0.253","192.168.0.250"};
/// string[] subnetList = new string[]{"255.255.255.0","255.255.255.0"};
/// o.ChangeTo(ipList,subnetList);
///
///
public ChangeIP()
{
moc = mc.GetInstances();
}
///cortrol
///IPAddr List
///subnetMask List
public void ChangeTo(string[] ipAddr, string[] subnetMask)
{
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"]) continue;
iObj = mo.GetMethodParameters("EnableStatic");
iObj["IPAddress"] = ipAddr;
iObj["SubnetMask"] = subnetMask;
oObj = mo.InvokeMethod("EnableStatic", iObj, null);
}
}
///cortrol
///IPAddr List
///subnetMask List
///gateway List
///gateway CostMetric List, example: 1
public void ChangeTo(string[] ipAddr, string[] subnetMask, string[] gateways, string[] gatewayCostMetric)
{
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"]) continue;
iObj = mo.GetMethodParameters("EnableStatic");
iObj["IPAddress"] = ipAddr;
iObj["SubnetMask"] = subnetMask;
oObj = mo.InvokeMethod("EnableStatic", iObj, null);
iObj = mo.GetMethodParameters("SetGateways");
iObj["DefaultIPGateway"] = gateways;
iObj["GatewayCostMetric"] = gatewayCostMetric;
oObj = mo.InvokeMethod("SetGateways", iObj, null);
}
}
///cortrol
///IPAddr List
///subnetMask List
///gateway List
///gateway CostMetric List, example: 1
///DNSServer List
public void ChangeTo(string[] ipAddr, string[] subnetMask, string[] gateways, string[] gatewayCostMetric, string[] dnsServer)
{
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"]) continue;
iObj = mo.GetMethodParameters("EnableStatic");
iObj["IPAddress"] = ipAddr;
iObj["SubnetMask"] = subnetMask;
oObj = mo.InvokeMethod("EnableStatic", iObj, null);
iObj = mo.GetMethodParameters("SetGateways");
iObj["DefaultIPGateway"] = gateways;
iObj["GatewayCostMetric"] = gatewayCostMetric;
oObj = mo.InvokeMethod("SetGateways", iObj, null);
iObj = mo.GetMethodParameters("SetDNSServerSearchOrder");
iObj["DNSServerSearchOrder"] = dnsServer;
oObj = mo.InvokeMethod("SetDNSServerSearchOrder", iObj, null);
}
}
///DHCPEnabled
public void EnableDHCP()
{
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"]) continue;
if (!(bool)mo["DHCPEnabled"])
{
iObj = mo.GetMethodParameters("EnableDHCP");
oObj = mo.InvokeMethod("EnableDHCP", iObj, null);
}
}
}
}
http://blog.csdn.net/greystar/archive/2008/02/01/2076211.aspx
他们设置了哪些标签:
C# C#技术 IP winform 更改IP功能源码 技术 源码
谁收藏了这个网址:
使用标签:C#, iP, 源码,时间:2008-2-1 14:04:03 | 相关网摘
C#实现更改IP功能源码
时间:2008-2-1 16:04:35 | 相关网摘
时间:2008-2-1 18:37:10 | 相关网摘
时间:2008-2-1 22:22:46 | 相关网摘
使用标签:C#, 更改IP功能源码,时间:2008-2-2 9:47:25 | 相关网摘
C#实现更改IP功能源码 - greystar的专栏 - CSDNBlog
使用标签:C#,时间:2008-2-2 11:11:46 | 相关网摘
C#实现更改IP功能源码
时间:2008-2-2 11:17:29 | 相关网摘
使用标签:C#,时间:2008-2-2 11:51:23 | 相关网摘
使用标签:C#,时间:2008-2-2 21:59:34 | 相关网摘
时间:2008-2-3 16:22:07 | 相关网摘
时间:2008-2-3 17:21:53 | 相关网摘
时间:2008-2-4 10:50:06 | 相关网摘
时间:2008-2-4 18:25:02 | 相关网摘
using System
时间:2008-2-5 10:21:57 | 相关网摘
时间:2008-2-5 13:19:16 | 相关网摘
时间:2008-2-5 15:50:59 | 相关网摘
时间:2008-2-7 12:01:30 | 相关网摘
时间:2008-2-9 20:55:32 | 相关网摘
时间:2008-2-12 10:00:56 | 相关网摘
使用标签:C#,时间:2008-2-13 8:48:03 | 相关网摘
时间:2008-2-13 13:30:48 | 相关网摘
时间:2008-2-13 21:11:10 | 相关网摘
using System;
using System.Management;
public class ChangeIP
{
private ManagementBaseObject iObj = null;
private ManagementBaseObject oObj = null;
private ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
private readonly ManagementObjectCollection moc;
///
/// example:
///
/// ChangeIP o = new ChangeIP();
/// string[] ipList = new string[]{"192.168.0.253","192.168.0.250"};
/// string[] subnetList = new string[]{"255.255.255.0","255.255.255.0"};
/// o.ChangeTo(ipList,subnetList);
///
///
public ChangeIP()
{
moc = mc.GetInstances();
}
///cortrol
///IPAddr List
///subnetMask List
public void ChangeTo(string[] ipAddr, string[] subnetMask)
{
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"]) continue;
iObj = mo.GetMethodParameters("EnableStatic");
iObj["IPAddress"] = ipAddr;
iObj["SubnetMask"] = subnetMask;
oObj = mo.InvokeMethod("EnableStatic", iObj, null);
}
}
///cortrol
///IPAddr List
///subnetMask List
///gateway List
///gateway CostMetric List, example: 1
public void ChangeTo(string[] ipAddr, string[] subnetMask, string[] gateways, string[] gatewayCostMetric)
{
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"]) continue;
iObj = mo.GetMethodParameters("EnableStatic");
iObj["IPAddress"] = ipAddr;
iObj["SubnetMask"] = subnetMask;
oObj = mo.InvokeMethod("EnableStatic", iObj, null);
iObj = mo.GetMethodParameters("SetGateways");
iObj["DefaultIPGateway"] = gateways;
iObj["GatewayCostMetric"] = gatewayCostMetric;
oObj = mo.InvokeMethod("SetGateways", iObj, null);
}
}
///cortrol
///IPAddr List
///subnetMask List
///gateway List
///gateway CostMetric List, example: 1
///DNSServer List
public void ChangeTo(string[] ipAddr, string[] subnetMask, string[] gateways, string[] gatewayCostMetric, string[] dnsServer)
{
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"]) continue;
iObj = mo.GetMethodParameters("EnableStatic");
iObj["IPAddress"] = ipAddr;
iObj["SubnetMask"] = subnetMask;
oObj = mo.InvokeMethod("EnableStatic", iObj, null);
iObj = mo.GetMethodParameters("SetGateways");
iObj["DefaultIPGateway"] = gateways;
iObj["GatewayCostMetric"] = gatewayCostMetric;
oObj = mo.InvokeMethod("SetGateways", iObj, null);
iObj = mo.GetMethodParameters("SetDNSServerSearchOrder");
iObj["DNSServerSearchOrder"] = dnsServer;
oObj = mo.InvokeMethod("SetDNSServerSearchOrder", iObj, null);
}
}
///DHCPEnabled
public void EnableDHCP()
{
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"]) continue;
if (!(bool)mo["DHCPEnabled"])
{
iObj = mo.GetMethodParameters("EnableDHCP");
oObj = mo.InvokeMethod("EnableDHCP", iObj, null);
}
}
}
}
时间:2008-2-15 9:19:10 | 相关网摘
时间:2008-2-15 13:03:23 | 相关网摘
使用标签:技术,时间:2008-2-17 22:21:02 | 相关网摘
时间:2008-2-22 19:55:27 | 相关网摘
时间:2008-4-1 15:50:10 | 相关网摘
时间:2008-7-7 9:46:44 | 相关网摘
C#实现更改IP功能源码 - greystar的专栏 - CSDNBlog