用户
购买联系
定制软件
智动博客助手
智动终级刷IP工具
首页
首页
/
编程技术
C#编程修改本机的IP,网关等
时间:
2010年04月12日
点击:
321
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
[]
...
{
"
10.22.21.111
"
,
"
192.168.10.9
"
}
;
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
[]
...
{
"
10.22.21.1
"
,
"
192.168.10.1
"
}
;
outPar
=
mo.InvokeMethod(
"
SetGateways
"
, inPar,
null
);
//
设置DNS
inPar
=
mo.GetMethodParameters(
"
SetDNSServerSearchOrder
"
);
inPar[
"
DNSServerSearchOrder
"
]
=
new
string
[]
...
{
"
179.32.42.4
"
,
"
179.32.42.5
"
}
;
outPar
=
mo.InvokeMethod(
"
SetDNSServerSearchOrder
"
,inPar,
null
);
break
;
}
}
/**/
/**/
/**/
///
<summary>
///
显示当前的ip,子网掩码,网关,DNS,网卡地址等信息
///
</summary>
static
void
ShowNetworkAdapterInfo()
...
{
Console.WriteLine(
"
****** Current Network Adapter Information ******
"
);
ManagementClass mc
=
new
ManagementClass(
"
Win32_NetworkAdapterConfiguration
"
);
ManagementObjectCollection moc
=
mc.GetInstances();
foreach
( ManagementObject mo
in
moc )
...
{
if
(
!
(
bool
) mo[
"
IPEnabled
"
] )
continue
;
Console.WriteLine(
"
\n SVC: '' MAC: []
"
, (
string
) mo[
"
Caption
"
],
(
string
) mo[
"
ServiceName
"
], (
string
) mo[
"
MACAddress
"
] );
string
[] addresses
=
(
string
[]) mo[
"
IPAddress
"
];
string
[] subnets
=
(
string
[]) mo[
"
IPSubnet
"
];
string
[] gateways
=
(
string
[]) mo[
"
DefaultIPGateway
"
];
string
[] dnses
=
(
string
[])mo[
"
DNSServerSearchOrder
"
];
Console.WriteLine(
"
Addresses :
"
);
foreach
(
string
sad
in
addresses)
Console.WriteLine(
"
\t''
"
, sad );
Console.WriteLine(
"
Subnets :
"
);
foreach
(
string
sub
in
subnets )
Console.WriteLine(
"
\t''
"
, sub );
Console.WriteLine(
"
Gateways:
"
);
foreach
(
string
gw
in
gateways )
Console.WriteLine(
"
\t''
"
, gw );
Console.WriteLine(
"
DNS:
"
);
foreach
(
string
dns
in
dnses )
Console.WriteLine(
"
\t''
"
, dns );
}
}
赞助商链接
热门内容
Navicat 中读取MYSQL数据显中文乱码问题解决方法
Proguard混淆提示类重复(Duplicate zip entry等提示)
phpstorm不安装apache就可以本地测试PHP
C# ListView随窗体大小自动改变列宽
MSScriptControl详解(可实现在C#等语言中调用JAVASCRIPT代码)
C#出现A generic error occurred in GDI+问题分析与解决
C#如何将控件设置为透明效果
钩子(HOOK)函数教程(一)
C#时常需要调用C++DLL问题详解
目录未找到或者无法访问:“ ./data/template”的解决
Sqlite:一个SQL搞定,记录存在不插入或者替换数据
C#实现自定义外观并可拖动和改变大小的窗口
相关内容
Android 实现模拟按键,模拟操作
Sqlite:一个SQL搞定,记录存在不插入或者替换数据
Nginx伪静态配置和常用Rewrite伪静态规则集锦
MQTT协议简要介绍
Navicat 中读取MYSQL数据显中文乱码问题解决方法
phpstorm不安装apache就可以本地测试PHP
Proguard混淆提示类重复(Duplicate zip entry等提示)
Android权限设置总汇
C#出现A generic error occurred in GDI+问题分析与解决
SQLite 简介
用PHP操作sqlite数据库
用JAVA操作SQLite
我们的产品
智动终极刷IP工具
智动博客助手
智动邮件搜索
联系我们
copyright © 2008 - 2021
智动软件
关于我们
联系我们
代理合作
投诉建议
常见问题
常用组件下载