社区
C#
帖子详情
设置本机IP地址
wkzjl
2004-07-08 01:40:35
请问设置本机IP地址。并检查没有和距域网的其它IP地址重复!!!
...全文
200
5
打赏
收藏
设置本机IP地址
请问设置本机IP地址。并检查没有和距域网的其它IP地址重复!!!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
xjj1982
2004-11-17
打赏
举报
回复
好像System中没有Management吧
haoliqi
2004-07-08
打赏
举报
回复
/// <code>
/// ArLi.CommonPrj.ChangeIP o = new ArLi.CommonPrj.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);
/// </code>
试了一下,没有成功!是需要重新启动吗
wkzjl
2004-07-08
打赏
举报
回复
怎么使用这个类啊
Bob
2004-07-08
打赏
举报
回复
C#实现更改IP功能(原码)
using System;
using System.Management;
namespace ArLi.CommonPrj {
public class ChangeIP {
/// <summary>
/// Build of ArLi 2003.6.3
/// </summary>
public static readonly System.Version myVersion = new System.Version(1,1);
private ManagementBaseObject iObj = null;
private ManagementBaseObject oObj = null;
private ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
private readonly ManagementObjectCollection moc;
/// <summary>
/// example:
/// <code>
/// ArLi.CommonPrj.ChangeIP o = new ArLi.CommonPrj.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);
/// </code>
/// </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);
}
}
}
}
}
lingyn
2004-07-08
打赏
举报
回复
看看system.net.dns类有没有该功能
第08章-
IP地址
--分类编址和无分类编址
课程内容如下:
IP地址
的用途、种类和表示方法
IP地址
的分类方法及怎样判别IP属于哪一类
IP地址
的地址块概念理解及地址块范围划分方法
IP地址
中的特殊地址详解
IP地址
中的单播、组播、广播简析 分类编址:通过
IP地址
...
Bat脚本自动
设置
本机
IP地址
title 以Admin权限
设置
本机
IP地址
PUSHD %~DP0 & cd /d "%~dp0" %1 %2 mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof :...
电脑如何更改
设置
本机
IP地址
更改为自己
设置
的
IP地址
参考: 1.桌面右下角右击打开网络
设置
2.选择更改适配器选项 3.右击网络选择WLAN属性 4.更改为自己
设置
的
IP地址
参考: https://zhidao.baidu.com/question/43844456.html ...
Qt修改
本机
IP地址
与获取
本机
IP地址
修改
本机
IP: QString set="netsh interface ip set address \"本地连接\" static
IP地址
子网掩码 网关; QProcess p; p.start(set); p.waitForStarted(); p.waitForFinished(); 获取
本机
IP: QString ...
如何配置Linux
ip地址
第三步:记住方框中的这几个信息,待会配置
IP地址
时需要使用到 第四步:在
本机
中按下win + R键,输入cmd,进入界面之后再输入ipconfig命令,找到Vmnet 8这块网卡的相关信息 我们可以发现第三步的子网IP192.168.164...
C#
110,538
社区成员
642,577
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章