如何只更改某个本地链接的IP?

matsu 2006-04-15 09:48:52
有两个网卡,就有两个本地链接,如何只更改指定某个本地链接的IP、NM、GW、MDNS、SDNS ?
...全文
158 2 点赞 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
matsu 2006-04-16
请具体写几句加在下面代码中
Function ChangeIP(IP As String, NM As String, GW As String, MDNS As String, SDNS As String) As String
'返回值说明:返回一个设置的中文说明.
Dim strComputer, objWMIService, colNetAdapters, strIPAddress, strSubnetMask
Dim strGateway, strGatewaymetric, strDNS, objNetAdapter, errEnable, errGateways, errDNS
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(IP) 'ip地址
strSubnetMask = Array(NM) '子网掩码
strGateway = Array(GW) '网关
strDNS = Array(MDNS, SDNS) '主DNS各备DNS
strGatewaymetric = Array(1)

For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
If errEnable = 0 And errGateways = 0 And errDNS = 0 Then
ChangeIP = "设置成功"
Else
If errEnable = 0 Then
ChangeIP = "IP地址和子网掩码设置成功, "
Else
ChangeIP = "IP地址或子网掩码设置失败, "
End If
If errGateways = 0 Then
ChangeIP = ChangeIP & "默认网关设置成功, "
Else
ChangeIP = ChangeIP & "默认网关设置失败, "
End If
If errDNS = 0 Then
ChangeIP = ChangeIP & "DNS设置成功"
Else
ChangeIP = ChangeIP & "DNS设置失败"
End If
End If
Next

End Function


Private Sub Command1_Click()
MsgBox ChangeIP("192.168.1.12", "255.255.255.0", "192.168.1.1", "201.96.112.133", "84.124.96.122")
End Sub
  • 打赏
  • 举报
回复
chenhui530 2006-04-15
netsh就可以了
  • 打赏
  • 举报
回复
相关推荐
发帖
网络编程
加入

1485

社区成员

VB 网络编程
申请成为版主
帖子事件
创建了帖子
2006-04-15 09:48
社区公告
暂无公告