2016-03-23 36 views
2

我有一个要求,以获得我使用下面的操作的方式从VBS PC的IP地址:获取IP,然后改变最后一个字节

strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > ''" 

Set objWMIService = GetObject("winmgmts://./root/CIMV2") 
Set colItems  = objWMIService.ExecQuery(strQuery, "WQL", 48) 

For Each objItem In colItems 
    If IsArray(objItem.IPAddress) Then 
     If UBound(objItem.IPAddress) = 0 Then 
      strIP = "IP Address: " & objItem.IPAddress(0) 
     Else 
      strIP = "IP Addresses: " & Join(objItem.IPAddress, ",") 
     End If 
    End If 
Next 

我然后使用下面的映射网络驱动器:

Option Explicit 
Dim objNetwork 
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile 

strDriveLetter = "Z:" 
strRemotePath = "\\10.121.34.140\c$" 
strUser = "user" 
strPassword = "Password" 
strProfile = "false" 

Set objNetwork = WScript.CreateObject("WScript.Network") 
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _ 
strProfile, strUser, strPassword 

我想不过做的是获得hostmachine(所以10.121.34.130)的知识产权和公正的八位位组更改为.140,并映射到这一点。

我该怎么做?

回答

2

InStrRev()Left()函数应该是你所需要的。

' Sample starting address... 
strIP = "10.121.34.130" 

' Get the index of the last period... 
i = InStrRev(strIP, ".") 

' Append the new last octet starting there... 
strIP = Left(strIP, i) & "140" 

或者,作为一个班轮:

strIP = Left(strIP, InStrRev(strIP, ".")) & "140" 

,或作为一个班轮创建完整的远程路径:

strIP = "\\" & Left(strIP, InStrRev(strIP, ".")) & "140\c$" 
+0

完美 - 我调整,使带材MyIPAddress和它的作品 - 很多谢谢! – Qazxswe

相关问题