vbscript static-ip-address

Cambie la puerta de enlace predeterminada utilizando vbscript alterando el último octeto de IP



static-ip-address (2)

Parece que resolví mi problema

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" ) strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > ''''" Set colNetAdapters = objWMIService.ExecQuery _ (strQuery) strIPAddress = (InputBox("IP address")) strSubnetMask = Array("255.255.255.0") strGateway = Left(strIPAddress, InStrRev(strIPAddress, ".")) & "254" strIPAddress = Array(strIPAddress) strGateway = Array(strGateway) 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

Encontré leyendo las variables antes de ponerlas en una matriz fue la clave

Se solicita al usuario que ingrese manualmente la IP, es decir, 192.168.0.2. La puerta de enlace cambiará a 192.168.0.254. Las funciones InStrRev () e Izquierda () deberían funcionar, pero no pueden hacer que funcione.

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" ) strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > ''''" Set colNetAdapters = objWMIService.ExecQuery _ (strQuery) strIPAddress = Array(InputBox("IP address")) strSubnetMask = Array("255.255.255.0") strGateway = Left(strIPAddress, InStrRev(strIPAddress, ".")) & "254" 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


Utilice Split () para obtener una matriz de octetos y cambie la última:

>> s = "192.168.0.2" >> a = Split(s, ".") >> a(3) = "254" >> WScript.Echo Join(a, ".") >> 192.168.0.254