是不是脩改本機上的IP呢???
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) 'Gateways
strDNS = Array(MDNS, SDNS) 'MAIN DNS AND SECOND 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地址或子网置 X, "
End If
If errGateways = 0 Then
ChangeIP = ChangeIP & "DEFAULT成功, "
Else
ChangeIP = ChangeIP & "DEFAULT X, "
End If
If errDNS = 0 Then
ChangeIP = ChangeIP & "DNS成功"
Else
ChangeIP = ChangeIP & "DNS X"
End If
End If
Next
End Function
Private Sub Command1_Click()
MsgBox ChangeIP(Winsock1.LocalIP, "255.255.255.0", "192.168.2.10", "192.168.2.10", "192.168.2.1")
End Sub
Private Sub Command2_Click()
MsgBox ChangeIP(Winsock1.LocalIP, "255.255.255.0", "192.168.2.1", "192.168.2.1", "192.168.2.10")
End Sub
Private Sub Form_Load()
If Winsock1.Index = "192.168.2.1" Then
Label2.Caption = "电信"
Else
Label2.Caption = "鉄通"
End If
End Sub