首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 数据库 第二书店 程序员

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);
}
}
}
}



他们设置了哪些标签:


C# C#技术 IP winform 更改IP功能源码 技术 源码

谁收藏了这个网址:


f4991417收录

使用标签:C#, iP, 源码,时间:2008-2-1 14:04:03 | 相关网摘

C#实现更改IP功能源码

chenzhifeng收录

时间:2008-2-1 16:04:35 | 相关网摘

scz26收录

时间:2008-2-1 18:37:10 | 相关网摘

rampart收录

使用标签:C#技术,时间:2008-2-1 20:27:21 | 相关网摘

c305303227收录

时间:2008-2-1 22:22:46 | 相关网摘

yanshijia01收录

使用标签:C#, 更改IP功能源码,时间:2008-2-2 9:47:25 | 相关网摘

C#实现更改IP功能源码 - greystar的专栏 - CSDNBlog

heimirror收录

使用标签:C#,时间:2008-2-2 11:11:46 | 相关网摘

C#实现更改IP功能源码

huzhongyi收录

时间:2008-2-2 11:17:29 | 相关网摘

love_virus收录

使用标签:C#,时间:2008-2-2 11:51:23 | 相关网摘

xk000收录

使用标签:C#,时间:2008-2-2 21:59:34 | 相关网摘

spy2008收录

时间:2008-2-3 16:22:07 | 相关网摘

mlhy20060406收录

时间:2008-2-3 17:21:53 | 相关网摘

marchonchina收录

时间:2008-2-4 10:50:06 | 相关网摘

dannyplus收录

使用标签:winform,时间:2008-2-4 11:22:00 | 相关网摘

wgqlj收录

时间:2008-2-4 18:25:02 | 相关网摘



using System

joeweng收录

时间:2008-2-5 10:21:57 | 相关网摘

jszhuzhi收录

时间:2008-2-5 13:19:16 | 相关网摘

windzb收录

时间:2008-2-5 15:50:59 | 相关网摘

dj3141592653收录

时间:2008-2-7 12:01:30 | 相关网摘

qthai收录

时间:2008-2-9 20:55:32 | 相关网摘

aififa收录

时间:2008-2-12 10:00:56 | 相关网摘

kwbin收录

使用标签:C#,时间:2008-2-13 8:48:03 | 相关网摘

TOMOROW收录

时间:2008-2-13 13:30:48 | 相关网摘

cm0201收录

时间: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);
}
}
}
}

ChessPlayer收录

时间:2008-2-15 9:19:10 | 相关网摘

greystar收录

时间:2008-2-15 13:03:23 | 相关网摘

sdhsdhsdhsdh收录

使用标签:技术,时间:2008-2-17 22:21:02 | 相关网摘

moon1981911收录

时间:2008-2-22 19:55:27 | 相关网摘

yangdj2000收录

时间:2008-4-1 15:50:10 | 相关网摘

andyye168收录

时间:2008-7-7 9:46:44 | 相关网摘

C#实现更改IP功能源码 - greystar的专栏 - CSDNBlog

网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
北京百联美达美数码科技有限公司 版权所有 京 ICP 证 020026 号
Copyright © 2000-2006, CSDN.NET, All Rights Reserved