代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
实现更改IP功能
作者:
dezai
/ 发布于
2014/7/23
/
616
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; ///<summary> /// 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); /// ///</summary> public ChangeIP() { moc = mc.GetInstances(); } ///<summary>cortrol</summary> ///<param name="ipAddr">IPAddr List</param> ///<param name="subnetMask">subnetMask List</param> 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); } } ///<summary>cortrol</summary> ///<param name="ipAddr">IPAddr List</param> ///<param name="subnetMask">subnetMask List</param> ///<param name="gateways">gateway List</param> ///<param name="gatewayCostMetric">gateway CostMetric List, example: 1</param> 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); } } ///<summary>cortrol</summary> ///<param name="ipAddr">IPAddr List</param> ///<param name="subnetMask">subnetMask List</param> ///<param name="gateways">gateway List</param> ///<param name="gatewayCostMetric">gateway CostMetric List, example: 1</param> ///<param name="dnsServer">DNSServer List</param> 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); } } ///<summary>DHCPEnabled</summary> 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); } } } }
试试其它关键字
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
dezai
贡献的其它代码
(
1065
)
.
双色球
.
列出所有物理网络适配器
.
快乐数的 Python 实现
.
计算当月还剩天数
.
猜属相
.
二十四小时时钟
.
每日一语
.
很酷的日历
.
超长日历表单
.
最简单的时钟
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3