Hallo,
hier im Forum wurde schon ab und zu die Frage gestellt, wie man den Ping-Befehl per Script nachbilden kann, z.B. im Threat http://atnotes.de/index.php/topic,2890.0.html
Letztendlich soll unser Domino-Server regelmäßig eine Liste von Netzwerkgeräten anpingen um zu prüfen, ob diese noch erreichbar bzw. im Einsatz sind.
Ich hatte bisher auch erfolgreich eine Routine im Einsatz, die sich verschiedener Funktionen aus der "wsock32.dll" bzw. "icmp.dll" bediente. Die Routine hatte ich damals irgendwo her kopiert, ohne sie im einzelnen genau zu verstehen. In den letzten Jahren funktionierte das auch problemlos... bis wir vor 2 Wochen mit unserem Domino-Server von einer 32bit-W2K3-Umgebung auf eine 64bit-W2K8-Umgebung umgezogen sind. Der Systemaufruf brachte unseren Domino-Server reproduzierbar zum Absturz(!).
Ich hätte nun gerne eine Ping-Routine, die sowohl auf dem Server in einer 64bit Umgebung als auch auf dem Client (derzeit noch 32Bit) funktioniert.
Könnte so etwas nicht evtl. über einen Java-Auruf relativ leicht Betriebssystemunabhängig umzusetzen sein? Ich kann leider kein Java, aber in Zusammenhang mit FTP bin ich vor einer Weile mal auf den nachfolgenden Code gestoßen.
Uselsx "*javacon"
Use "JakartaFtpWrapper"
Sub Initialize
'** This is a test of using the JakartaFtpWrapper class/script library,
'** called using LS2J in a LotusScript agent. You'll need Notes 6.x
'** or higher, and you'll have to include:
'** Uselsx "*javacon"
'** Use "JakartaFtpWrapper"
'** in the options section of the agent. For more information on the
'** class itself, please see the comments in the script library.
'** This agent was originally written by Julian Robichaux, and is available
'** at http://www.nsftools.com . You can use it in any way you'd like, just
'** don't pretend like you wrote it.
'** This is version 1.0 of the agent.
On Error Goto processError
'** yes, we'll need all four of these objects to access a single Java class
Dim jSession As New JavaSession
Dim ftpClass As JavaClass
Dim ftpClient As JavaObject
Dim jError As JavaError
'** get the FTP class and instantiate an instance of it
Set ftpClass = jSession.GetClass("JakartaFtpWrapper")
Set ftpClient = ftpClass.CreateObject
Dim host As String, user As String, pwd As String
host = "xxx"
user = "user"
pwd = "password"
'** try to log in
If ftpClient.connectAndLogin(host, user, pwd) Then
Print "Successfully connected to " + host
Print "Welcome message is:" + Chr(10) + ftpClient.getReplyString()
Print "System type is: " + ftpClient.getSystemName()
Call ftpClient.logout()
Call ftpClient.disconnect()
Else
'** either we couldn't connect or we couldn't login (the connectAndLogin
'** method doesn't differentiate -- you could call the connect and the login
'** methods separately if you needed to know)
Print "Could not connect or login!"
End If
Das realisieren eines "Ping-Tests" in Java ist laut Internet wohl auch kein besonderes Problem. Auf http://stackoverflow.com/questions/11506321/java-code-to-ping-an-ip-address habe ich gefunden:
public static void main(String[] args) throws UnknownHostException, IOException {
String ipAddress = "127.0.0.1";
InetAddress inet = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
System.out.println(inet.isReachable(5000) ? "Host is reachable" : "Host is NOT reachable");
ipAddress = "173.194.32.38";
inet = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
System.out.println(inet.isReachable(5000) ? "Host is reachable" : "Host is NOT reachable");
}
Gibt es hier jemanden mit Java-Kenntnissen, der mir sagen kann, ob das grundsätzlich auf diesem Weg möglich sein könnte oder der ggf. sogar etwas Code liefern kann?
Danke & Grüße,
Gregor
Über das WMI-Objekt scheint es auf dem 32bit-Client und auch auf dem 64bit-Server zu laufen.
Vielen Dank.
%REM
Function Ping
Description: Gibt die IP-Adresse zurück, wenn der Rechner pingbar ist...
Quelle: http://larsmichelsen.com/vbs/quickie-how-to-ping-a-host-in-vbs-i-got-two-ways/
%END REM
Function Ping(strHost As String) As String
Dim oPing, oWMIService, bReturn
Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address='" & strHost & "'")
ForAll oRetStatus In oPing
If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
Ping = ""
' WScript.Echo "Status code is " & oRetStatus.StatusCode
Else
Ping = oRetStatus.ProtocolAddress
' Wscript.Echo "Bytes = " & vbTab & oRetStatus.BufferSize
' Wscript.Echo "Time (ms) = " & vbTab & oRetStatus.ResponseTime
' Wscript.Echo "TTL (s) = " & vbTab & oRetStatus.ResponseTimeToLive
End If
Set oRetStatus = Nothing
End ForAll
Set oPing = Nothing
End Function