主题:请问大虾,在C#如何能更改自己的IP地址!谢谢!
happyw2004
[专家分:840] 发布于 2006-06-23 16:54:00
请问大虾,在C#如何能更改自己的IP地址!谢谢!
回复列表 (共2个回复)
沙发
zhxatx [专家分:500] 发布于 2006-06-23 17:42:00
方法有两个:
修改注册表~~!详细看下面连接
http://www.19b.cn/asppost13/web241094.htm
使用api:(一下代码纯属抄袭,不是我写的,只是贴出来,告诉你有这么一个API函数)
Description
Sets the IP address of a computer to 192.168.1.141, and sets the IP gateway to 192.168.1.100.
Script Code
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
板凳
﹎№1╃ωǒ [专家分:0] 发布于 2006-07-28 19:59:00
怎么更改自己的IP地址
我来回复