Hi! I need to ping some ips like:
I have made a macro that need to be compatible for linux and windows, in windows is currently working but in linux i don’t know how to do it.
here is my code:
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Function CheckOS()
Dim CheckOSO As String
CheckOS = Null
CheckOSO = Application.OperatingSystem
If InStr(1, LCase(CheckOSO), "windows") <> 0 Then
CheckOS = True
Else
CheckOS = False
End If
End Function
Function Ping(strip)
Dim objShell, boolcode
Ping = Null
boolcode = 3
If CheckOS = True Then
Set objshell = CreateObject("Wscript.Shell")
boolcode = objshell.Run("ping -n 1 -w 1000 " & strip, 0, 1)
Else
'put here the linux instructions to ping
End If
If boolcode = 0 Then
Ping = True
Else
If boolcode = 1 Then
Ping = False
Else
Ping = Null
End If
End If
End Function
Sub PingSystem()
Dim strip As String
Do Until Worksheets("VMs").Range("D1").Value = "STOP"
Worksheets("VMs").Range("D1").Value = "TESTING"
For introw = 3 To Worksheets("VMs").Cells(Rows.Count, 16).End(xlUp).Row
strip = Worksheets("VMs").Cells(introw, 16).Value
If Ping(strip) = True Then
Worksheets("VMs").Cells(introw, 4).Interior.Color = RGB(254, 254, 160)
Worksheets("VMs").Cells(introw, 4).Font.Color = RGB(0, 0, 0)
Worksheets("VMs").Cells(introw, 4).Value = "y"
'Application.Wait (Now + TimeValue("0:00:01"))'
Worksheets("VMs").Cells(introw, 4).Font.Color = RGB(0, 200, 0)
Worksheets("VMs").Cells(introw, 4).Interior.Color = RGB(223, 236, 212)
Else
If Ping(strip) = False Then
Worksheets("VMs").Cells(introw, 4).Interior.Color = RGB(254, 254, 160)
Worksheets("VMs").Cells(introw, 4).Font.Color = RGB(0, 0, 0)
Worksheets("VMs").Cells(introw, 4).Value = "n"
'Application.Wait (Now + TimeValue("0:00:01"))'
Worksheets("VMs").Cells(introw, 4).Font.Color = RGB(200, 0, 0)
Worksheets("VMs").Cells(introw, 4).Interior.Color = RGB(252, 174, 148)
Else
Worksheets("VMs").Cells(introw, 4).Interior.Color = RGB(254, 254, 160)
Worksheets("VMs").Cells(introw, 4).Font.Color = RGB(0, 0, 0)
Worksheets("VMs").Cells(introw, 4).Value = "err"
'Application.Wait (Now + TimeValue("0:00:01"))'
Worksheets("VMs").Cells(introw, 4).Font.Color = RGB(200, 0, 0)
Worksheets("VMs").Cells(introw, 4).Interior.Color = RGB(252, 174, 148)
End If
End If
If Worksheets("VMs").Range("D1").Value = "STOP" Then
Exit For
End If
Next
Worksheets("VMs").Range("D1").Value = "STOP"
Loop
Worksheets("VMs").Range("D1").Value = "IDLE"
End Sub
Sub stop_ping()
Worksheets("VMs").Range("D1").Value = "STOP"
End Sub
pls help me!
[erAck: edited to make that an actual code block (using ```text because otherwise Basic becomes ugly coloured)]