none
display only the last octet of the ipv4 RRS feed

  • Question

  • Hi,
    below the code to display the ipv4 only, I would like to display only the last octet help me please ;

    
    
    strComputer = "."
    On Error Resume Next
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled = 'True'")
    For Each objIP in colSettings
       For i=LBound(objIP.IPAddress) to UBound(objIP.IPAddress)
          If InStr(objIP.IPAddress(i),":") = 0 Then Echo objIP.IPAddress(i)
       Next
    Next

    ******************************************************

    thank you Cordially.


    Thursday, January 10, 2019 10:34 AM

All replies

  • One solution would be:

    strComputer = "."
    On Error Resume Next
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled = 'True'")
    For Each objIP in colSettings
       For i=LBound(objIP.IPAddress) to UBound(objIP.IPAddress)
          If (InStr(objIP.IPAddress(i),":") = 0) Then
              strIP = objIP.IPAdress(i)
              intLastDot = InStrRev(strIP, ".")
              Wscript.Echo Mid(strIP, intLastDot + 1)
          End If
       Next
    Next
    


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Thursday, January 10, 2019 3:26 PM
  • Hello,

    didn't work for me but i have another one worked well :

    Set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE")
    
    For Each IPConfig In IPConfigSet
     If Not IsNull(IPConfig.IPAddress) Then 'MsgBox IPConfig.IPAddress(0), vbInformation
     
       
    strIP = IPConfig.IPAddress(0)
    
    intLastDecimal = 1
    
    intLastDecimal = InStrRev(strIP, ".") 
    strNewIP = Right(strIP,Len(strIP) - intLastDecimal)
    'strNewIP = Left(strIP, intLastDecimal ) &  " -- " & Right(strIP, intLastDecimal ) 
    
      Echo  "" & strNewIP   '&  "" & Now
      End if
    Next

    Monday, January 14, 2019 8:55 AM