diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bbf1e23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +Backup_* +demos +*.bak diff --git a/Icon256-32.ico b/Icon256-32.ico new file mode 100644 index 0000000..f70f635 Binary files /dev/null and b/Icon256-32.ico differ diff --git a/pinz.au3 b/pinz.au3 new file mode 100644 index 0000000..61bbf0a --- /dev/null +++ b/pinz.au3 @@ -0,0 +1,627 @@ +#NoTrayIcon +#Region ;**** Directives created by AutoIt3Wrapper_GUI **** +#AutoIt3Wrapper_Icon=Icon256-32.ico +#AutoIt3Wrapper_Outfile=pinz.exe +#AutoIt3Wrapper_UseUpx=y +#AutoIt3Wrapper_Change2CUI=y +#AutoIt3Wrapper_Res_Description=pinz - Ping mit optischer Laufzeitdarstellung - znil.net +#AutoIt3Wrapper_Res_Fileversion=0.0.0.100 +#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y +#AutoIt3Wrapper_Res_SaveSource=y +#AutoIt3Wrapper_Res_Language=1031 +#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** +#include-once +#Include +#Include +#Include +#include + +; **************************************************************************************** +; ## ## ### ######## #### ### ######## ## ######## ###### +; ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## +; ## ## ## ## ## ## ## ## ## ## ## ## ## ## +; ## ## ## ## ######## ## ## ## ######## ## ###### ###### +; ## ## ######### ## ## ## ######### ## ## ## ## ## +; ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## +; ### ## ## ## ## #### ## ## ######## ######## ######## ###### +; **************************************************************************************** + +; *************************************************************************************************************************************** +; Nachfolgendes wird für die "PingLikeMicrosoft" Function gebraucht +; Die wurde benötigt da ich bei der in AutoIt eingebauten Ping-Funktion nicht die Paket-Größe ändern kann +; Die Funktion habe ich hier gefunden: http://www.autoitscript.com/forum/topic/129525-ping-help/ +Global Const $IP_SUCCESS = 0 +Global Const $IP_STATUS_BASE = 11000 +Global Const $IP_BUF_TOO_SMALL = ($IP_STATUS_BASE + 1) +Global Const $IP_DEST_NET_UNREACHABLE = ($IP_STATUS_BASE + 2) +Global Const $IP_DEST_HOST_UNREACHABLE = ($IP_STATUS_BASE + 3) +Global Const $IP_DEST_PROT_UNREACHABLE = ($IP_STATUS_BASE + 4) +Global Const $IP_DEST_PORT_UNREACHABLE = ($IP_STATUS_BASE + 5) +Global Const $IP_NO_RESOURCES = ($IP_STATUS_BASE + 6) +Global Const $IP_BAD_OPTION = ($IP_STATUS_BASE + 7) +Global Const $IP_HW_ERROR = ($IP_STATUS_BASE + 8) +Global Const $IP_PACKET_TOO_BIG = ($IP_STATUS_BASE + 9) +Global Const $IP_REQ_TIMED_OUT = ($IP_STATUS_BASE + 10) +Global Const $IP_BAD_REQ = ($IP_STATUS_BASE + 11) +Global Const $IP_BAD_ROUTE = ($IP_STATUS_BASE + 12) +Global Const $IP_TTL_EXPIRED_TRANSIT = ($IP_STATUS_BASE + 13) +Global Const $IP_TTL_EXPIRED_REASSEM = ($IP_STATUS_BASE + 14) +Global Const $IP_PARAM_PROBLEM = ($IP_STATUS_BASE + 15) +Global Const $IP_SOURCE_QUENCH = ($IP_STATUS_BASE + 16) +Global Const $IP_OPTION_TOO_BIG = ($IP_STATUS_BASE + 17) +Global Const $IP_BAD_DESTINATION = ($IP_STATUS_BASE + 18) +Global Const $IP_ADDR_DELETED = ($IP_STATUS_BASE + 19) +Global Const $IP_SPEC_MTU_CHANGE = ($IP_STATUS_BASE + 20) +Global Const $IP_MTU_CHANGE = ($IP_STATUS_BASE + 21) +Global Const $IP_UNLOAD = ($IP_STATUS_BASE + 22) +Global Const $IP_ADDR_ADDED = ($IP_STATUS_BASE + 23) +Global Const $IP_GENERAL_FAILURE = ($IP_STATUS_BASE + 50) +Global Const $MAX_IP_STATUS = ($IP_STATUS_BASE + 50) +Global Const $IP_PENDING = ($IP_STATUS_BASE + 255) +Global Const $PING_TIMEOUT = 500 +Global Const $WS_VERSION_REQD = 0x101 +Global Const $MIN_SOCKETS_REQD = 1 +Global Const $SOCKET_ERROR = -1 +Global Const $INADDR_NONE = 0xFFFFFFFF +Global Const $MAX_WSADescription = 256 +Global Const $MAX_WSASYSStatus = 128 +If @AutoItX64 Then Exit 0 * MsgBox(16, @ScriptName & " - Error", "ICMP structures only designed for 32-Bit Version") +Global Const $ICMP_OPTIONS = _ +"ubyte Ttl;" & _ +"ubyte Tos;" & _ +"ubyte Flags;" & _ +"ubyte OptionsSize;" & _ +"ptr OptionsData" ; Options Data +Global Const $tagICMP_ECHO_REPLY = _ +"ulong Address;" & _ ; IPAddr +"ulong Status;" & _ +"ULONG RoundTripTime;" & _ +"USHORT DataSize;" & _ +"USHORT Reserved;" & _ +"ptr Data;" & _ +$ICMP_OPTIONS +; Vorstehendes wird für die "PingLikeMicrosoft" Function gebraucht +; *************************************************************************************************************************************** + +Dim $a_PingError[5] ; Enthält den Text für den Rückgabewert von "PingLikeMicrosoft" bei Fehlern +Dim $i_PingTime ; hier steht drin welche Laufzeit der letzte Ping hatte - oder 0 wenn es nicht geklappt hat +Dim $i_LastPingTime ; Wir merken uns für jeden Durchlauf die Pinglaufzeit vom mal davor für Vergleiche +Dim $s_IP ; IP-Adresse des Hosts den wir anpingen +Dim $s_DNS ; DNS-Name des Host den wir anpingen - wird vom DNS-Server abgefragt +Dim $s_TargetHost ; Der vom Benutzer übergebende Zielhost als IP oder DNS oder NetBIOS-Name +Dim $i_n = 4 ; Anzahl der Pings, Standard ist 4 mal +Global $i_Counter = 0 ; Falls der Benutzer uns eine Anzahl n übergeben hat zählen wir hiermit mit wie oft wir schon gepingt haben +Dim $i_Pause = 1000 ; Wieviel Pause soll zwischen den einzelnen Pings erfolgen? +Dim $s_Result ; In dieser Variablen wird die Ausgabezeile zusammengebaut +Dim $i_LastResultLen ; Länge der letzten, vorherigen Ausgabezeile für Vergleiche +Dim $i_PercentPingTime ; Pinglaufzeit in Prozent im Verhältnis zum noch freien Platz in der Zeile +Dim $b_EndlessPing = False ; Wird auf True gesetzt falls der Benutzer -t angegeben hat +Dim $i_WindowSizeHorizontal ; Wieviele Zeichen passen in eine Zeile - ausgelesen aus der Windows-Registry +Dim $s_temp, $i_temp ; Temporäre Variablen +Dim $i_TimeOut = 4000 ; Maximale Wartezeit auf einen Ping +Global $i_Packets_Send = 0 ; Zähler - wieviele Pings wurden gesendet +Global $i_Packets_Receive = 0 ; Zähler - wieviele Antworten auf Pings haben wir erhalten? +Global $i_PingTimeMin = 0 ; Schnellster Ping +Global $i_PingTimeMax = 9999999999 ; langsamster Ping +Global $i_timer ; Hilfsvariable mit der wir die Zeit messen in unserer Schleife +Global $b_SkipPing = False ; Hilfsvariable die gesetzt wird um das pingen zu überspringen +Global $i_Error +Global $i_Extended + +; Das normale ping sendet 32 Bytes ... das machen wir auch in dem wir eine Zeichenfolge dieser Länge senden. +; Indem wir die Zeichenfolge verlängern oder verkürzen können wir diesen Wert später anpassen +; 1 2 3 +; 12345678901234567890123456789032 +Dim $s_Payload = "abcdefghijklmnopqrstuvwabcdefghi" ; 32 Bytes! +Dim $s_Payload = "pinz -- ping von http://znil.net" ; 32 Bytes! + + +; Wir holen uns einen Zeiger auf das aktuelle Fenster - brauchen wir für das Abfangen von STRG + C +Global $sDllValue, $DOSBOCHandle +$sDllValue = DllCall( "Kernel32.dll","hwnd","GetConsoleWindow") +$DOSBOCHandle = $sDllValue[0] + + +; Anzahl der Zeichen pro Zeile ermitteln aus den Default Werten der Registry +$s_temp = Hex(RegRead("HKCU\Console", "WindowSize"), 4) ; in den letzten 4 Zeichen steht die Horizontale Breite +$i_WindowSizeHorizontal = Dec($s_temp) + + +; 10 20 30 40 50 60 70 80 +; 12345678901234567890123456789012345678901234567890123456789012345678901234567890 +Dim $s_Header = _ + "+------------------------------------------------------------------------------" & @CRLF & _ + "| pinz.exe - Version " & FileGetVersion(@ScriptName) & @CRLF & _ + "+------------------------------------------------------------------------------" & @CRLF & _ + "| 2015 von Bernhard Linz für http://znil.net - Kontakt: Bernhard@znil.net" & @CRLF & _ + "+------------------------------------------------------------------------------" & @CRLF & _ + @CRLF + +; 10 20 30 40 50 60 70 80 +; 12345678901234567890123456789012345678901234567890123456789012345678901234567890 +Dim $s_HilfeText = _ + "Pinz - Ein ping Programm welches die Laufzeit des Pings optisch darstellt" & @CRLF & _ + "-------------------------------------------------------------------------------" & @CRLF & _ + @CRLF & _ + "Aufruf: " & @CRLF & _ + @CRLF & _ + @ScriptName & " Ziel [-t]" & @CRLF & _ + @CRLF & _ + "Ziel : IP-Adresse (IPv4 oder IPv6) oder NetBIOS-Name oder" & @CRLF & _ + " DNS-Name des Ziels" & @CRLF & _ + @CRLF & _ + " -t : Kontinuierlich pingen bis das Programm per STRG + C gestoppt" & @CRLF & _ + " wird" & @CRLF & _ + @CRLF & _ + " -n Anzahl : Anzahl von Pinganforderungen die gesendet werden sollen," & @CRLF & _ + " Standard ist 4" & @CRLF & _ + @CRLF & _ + " -l Größe : Größe der Datenpakete in Bytes, STandard sind 32 Bytes" & @CRLF & _ + @CRLF & _ + " -p Zeit : Pause zwischen den einzelnen Pings in Millisekunden," & @CRLF & _ + " Standard ist 1.000 = 1s" & @CRLF & _ + @CRLF & _ + " -w Zeitlimit : Zeitlimit in Millisekunden für eine Rückmeldung." & @CRLF & _ + @CRLF & _ + "+------------------------------------------------------------------------------" & @CRLF & _ + "| pinz.exe ist FREEWARE!" & @CRLF & _ + "| Kopieren, weitergeben ausdrücklich erlaubt!" & @CRLF & _ + "| Die jeweils aktuelleste Version und Anleitungen findet Ihr unter:" & @CRLF & _ + "| http://znil.net/index.php?title=pinz" & @CRLF & _ + "+------------------------------------------------------------------------------" & @CRLF + +; Fehlertexte für "PingLikeMicrosoft" setzen +$a_PingError[1] = "Zielhost ist Offline" +$a_PingError[2] = "Zielhost nicht erreichbar " +$a_PingError[3] = "unbekanntes Ziel" +$a_PingError[4] = "Netzwerkfehler" + +; ************************************************************************************* +; ######## ## ## ## ## ###### ######## #### ####### ## ## ###### +; ## ## ## ### ## ## ## ## ## ## ## ### ## ## ## +; ## ## ## #### ## ## ## ## ## ## #### ## ## +; ###### ## ## ## ## ## ## ## ## ## ## ## ## ## ###### +; ## ## ## ## #### ## ## ## ## ## ## #### ## +; ## ## ## ## ### ## ## ## ## ## ## ## ### ## ## +; ## ####### ## ## ###### ## #### ####### ## ## ###### +; ************************************************************************************* + + +; # # # ##### ### ##### ####### ####### # # +; # # ## # # # # # # # # # ## ## +; # # # # # # # # # # # # # # # +; # # # # # ##### # ##### # # ##### # # # +; ####### # # # # # # # # # # # +; # # # ## # # # # # # # # # +; # # # # ##### ### ####### ####### ####### # # +;####### +; _ANSI2OEM löst das Problem mit dem Umlauten und anderen Sonderzeichen. Es wandelt Text so um das er korrekt in der DOS-Box dargestellt wird +; So können hier im Quellcode auch Umlaute verwendet werden (in den Textausgaben) und diese werden dann korrekt dargestellt +Func _ANSI2OEM($text) + $text = DllCall('user32.dll', 'Int', 'CharToOem', 'str', $text, 'str', '') + Return $text[2] + ;Return $text +EndFunc ;==>_ANSI2OEM + + +; # # # +; # # # # ###### ###### # # # # #### #### ###### ##### ###### # # +; # # # # # # # # # # # # # # # # # ## # +; ####### # # ##### ##### # # # # #### # ##### ##### ##### # # # +; # # # # # # ####### # # # # ### # # # # # # # +; # # # # # # # # # # # # # # # # # # # ## +; # # # ###### # ###### # # #### #### #### ###### ##### ###### # # +;####### +; Hilfsroutine die den Hilfetext ausgibt +Func _HilfeAusgeben() + ConsoleWrite(_ANSI2OEM($s_Header)) + ConsoleWrite(_ANSI2OEM($s_HilfeText)) +EndFunc ;==>_HilfeAusgeben + + +; ##### ####### ###### # ##### +; # # # # # # # # +; # # # # # # +; # # ###### # # +; # # # # # # +; # # # # # # # # +; ##### # # # ####### ##### +;####### ####### +; die Tastenkombination STRG +C abfangen um dann eine Zusammenfassung auszugeben +Func _CTRL_C() + If WinActive( $DOSBOCHandle, "" ) Then + ; Unser Fenster ist gerade aktiv! + _WriteStatistics() + ; Abfangen von STRG + C aufheben + HotKeySet( "^c" ) + Exit $i_Error + Else + ; Es wurde zwar STRG + C gedrückt - das war aber nicht für uns bestimmt + ; Wir senden deshalb den Tastendruck weiter + HotKeySet( "^c" ) + Send( "^c" ) + HotKeySet( "^c","_CTRL_C" ) + EndIf +EndFunc + + +; # # ##### +; # # # ##### # ##### ###### # # ##### ## ##### # #### ##### # #### #### +; # # # # # # # # # # # # # # # # # # # # +; # # # # # # # ##### ##### # # # # # #### # # # #### +; # # # ##### # # # # # ###### # # # # # # # +; # # # # # # # # # # # # # # # # # # # # # # # +; ## ## # # # # ###### ##### # # # # # #### # # #### #### +;####### +Func _WriteStatistics() + Local $i_Packets_Lost + If $i_Packets_Send > 0 Then + If $i_PingTimeMax = 9999999999 Then + $i_PingTimeMax = 0 + EndIf + $i_Packets_Lost = Int(($i_Packets_Send - $i_Packets_Receive) / $i_Packets_Send * 100) + ; eben noch sicher gehen das der Prozentwert nicht größer als 100 oder kleiner als 0 ist - kann passieren wenn vor dem ersten Ping schon abgebrochen wird + If $i_Packets_Lost < 0 Then + $i_Packets_Lost = 0 + EndIf + If $i_Packets_Lost > 100 Then + $i_Packets_Lost = 100 + EndIf + ConsoleWrite(@CRLF) + ConsoleWrite(_ANSI2OEM("PingZ-Statistik für " & $s_IP & ":" & @CRLF)) + ConsoleWrite(" Pakete: Gesendet = " & $i_Packets_Send & ", Empfangen = " & $i_Packets_Receive & ", Verloren = " & ($i_Packets_Send - $i_Packets_Receive) & @CRLF) + ConsoleWrite(" (" & $i_Packets_Lost & "% Verlust)," & @CRLF) + ConsoleWrite("Ca. Zeitangaben in Millisekunden:" & @CRLF) + ConsoleWrite(" Minimum = " & $i_PingTimeMin & "ms, Maximum = " & $i_PingTimeMax & "ms, Mittelwert = " & Int(($i_PingTimeMin + $i_PingTimeMax) / 2) & "ms" & @CRLF) + EndIf +EndFunc + + + +; Nachfolgendes wird für die "PingLikeMicrosoft" Function gebraucht +; Die wurde benötigt da ich bei der in AutoIt eingebauten Ping-Funktion nicht die Paket-Größe ändern kann +; Die Funktion habe ich hier gefunden: http://www.autoitscript.com/forum/topic/129525-ping-help/ +Func _IcmpCustomPayload($sAddress, $sDataToSend, ByRef $ECHO, $PING_TIMEOUT = 4000) ; ECHO As ICMP_ECHO_REPLY +; $ECHO receives an ICMP_ECHO_REPLY on success +; by Prog@ndy, used VBSource from http://vbnet.mvps.org/index.html?code/internet/ping.htm +; on success return 1 , else 0 +Local $return = 0, $error = 0 +;~ 'If Ping succeeds : +;~ '.RoundTripTime = time in ms for the ping to complete, +;~ '.Data is the data returned (NULL terminated) +;~ '.Address is the Ip address that actually replied +;~ '.DataSize is the size of the string in .Data +;~ '.Status will be 0 +;~ ' +;~ 'If Ping fails .Status will be the error code +Local $WSOCK32DLL = DllOpen("wsock32.dll") +; use Icmp.dll for: Windows 2000 Server and Windows 2000 Professional +;Local $ICMPDLL = DllOpen("icmp.dll") +; use Iphlpapi.dll for: Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP +Local $ICMPDLL = DllOpen("Iphlpapi.dll") +Local $hPort ;As Long +Local $dwAddress ;As Long +Local $INADDR_NONE = -1 +;~ If Not StringRegExp($sAddress,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") Then +;~ TCPStartup() +;~ $sAddress = TCPNameToIP($sAddress) +;~ TCPShutdown() +;~ EndIf +;~ 'convert the address into a long representation +$dwAddress = DllCall($WSOCK32DLL, "uint", "inet_addr", "str", $sAddress) +$dwAddress = $dwAddress[0] +;~ 'if a valid address.. +If $dwAddress <> $INADDR_NONE Or $sAddress = "255.255.255.255" Then + ;~ 'open a port + $hPort = DllCall($ICMPDLL, "hwnd", "IcmpCreateFile") + $hPort = $hPort[0] + ;~ 'and if successful, + If $hPort Then + $ECHO = DllStructCreate($tagICMP_ECHO_REPLY & ";char[355]") + ;~ 'ping it. + Local $ret = _IcmpSendEcho($hPort, _ + $dwAddress, _ + $sDataToSend, _ + StringLen($sDataToSend), _ + 0, _ + DllStructGetPtr($ECHO), _ + DllStructGetSize($ECHO), _ + $PING_TIMEOUT, _ + $ICMPDLL) + ;~ 'return the status as ping succes and close + $error = DllStructGetData($ECHO, "Status") + If $error = $IP_SUCCESS Then $return = 1 + DllCall($ICMPDLL, "uint", "IcmpCloseHandle", "hwnd", $hPort) + EndIf +Else + ;~ 'the address format was probably invalid + $return = 0 + $error = $INADDR_NONE +EndIf +DllClose($WSOCK32DLL) +DllClose($ICMPDLL) +Return SetError($error, 0, $return) +EndFunc ;==>_IcmpCustomPayload +; by BugFix, modified by Prog@ndy +; für 1000 < @error < 1004 is der error von Dllcall. Die DllCall-Fehlernummer ist dabei @error/1000 +Func _IcmpSendEcho($IcmpHandle, $DestinationAddress, $RequestData, $RequestSize, $RequestOptions, $ReplyBuffer, $ReplySize, $Timeout, $ICMPDLL = "icmp.dll") +Local $ret = DllCall($ICMPDLL, "dword", "IcmpSendEcho", _ + "hwnd", $IcmpHandle, _ + "uint", $DestinationAddress, _ + "str", $RequestData, _ + "dword", $RequestSize, _ + "ptr", $RequestOptions, _ + "ptr", $ReplyBuffer, _ + "dword", $ReplySize, _ + "dword", $Timeout) +If @error Then Return SetError(@error+1000, 0, 0) +Return $ret[0] +EndFunc ;==>_IcmpSendEcho + +Func _PingLikeMicrosoft($DestinationAddress, $Timeout = 4000, $sPayLoad = "abcdefghijklmnopqrstuvwabcdefghi") +; function created by CUNNINGT +Local $ECHORet +Local $pingSucess = _IcmpCustomPayload($DestinationAddress, $sPayLoad, $ECHORet, $Timeout) +If @error Then + Switch @error + Case $IP_REQ_TIMED_OUT + $i_Error = 1 + $i_Extended = 1 + Return SetError(1, 1) + Case $IP_DEST_HOST_UNREACHABLE + $i_Error = 1 + $i_Extended = 2 + Return SetError(1, 2) + Case $IP_BAD_DESTINATION + $i_Error = 1 + $i_Extended = 3 + Return SetError(1, 3) + Case Else + $i_Error = 1 + $i_Extended = 4 + Return SetError(1, 4) + EndSwitch +Else + $i_Error = 0 + $i_Extended = 0 + Return DllStructGetData($ECHORet, "RoundTripTime") +EndIf + +EndFunc ;==>_PingLikeMicrosoft + +; **************************************** +; ## ## ### #### ## ## +; ### ### ## ## ## ### ## +; #### #### ## ## ## #### ## +; ## ### ## ## ## ## ## ## ## +; ## ## ######### ## ## #### +; ## ## ## ## ## ## ### +; ## ## ## ## #### ## ## +; **************************************** + +; falls keine Parameter angegeben wurden die Hilfe ausgeben +If $CmdLine[0] = 0 Then + _HilfeAusgeben() + Exit 0 +EndIf +;testen ob der Parameter 1 ist auf "/?" testen und ebenfalls Hilfe ausgeben +If $CmdLine[1] = "/?" Then + _HilfeAusgeben() + Exit 0 +EndIf + +; Die übergebenen Parameter auswerten und zuordnen +For $i = 1 To $CmdLine[0] + If StringLeft($CmdLine[$i], 2) = "-t" Then + ; Dauerping! + $b_EndlessPing = True + ElseIf StringLeft($CmdLine[$i], 2) = "-n" Then + ; Bestimmte Anzahl von Ping senden + If $CmdLine[0] >= ($i + 1) Then + $i = $i + 1 + $i_n = Int($CmdLine[$i]) + If $i_n < 1 Then + $i_n = 4 + EndIf + Else + ConsoleWrite(_ANSI2OEM("Der Wert muss für die Option angegeben werden: -n" & @CRLF)) + Exit 1 + EndIf + ElseIf StringLeft($CmdLine[$i], 2) = "-p" Then + + If $CmdLine[0] >= ($i + 1) Then + $i = $i + 1 + $i_Pause = Int($CmdLine[$i]) + Else + ConsoleWrite(_ANSI2OEM("Der Wert muss für die Option angegeben werden: -p" & @CRLF)) + Exit 1 + EndIf + ElseIf StringLeft($CmdLine[$i], 2) = "-l" Then + If $CmdLine[0] >= ($i + 1) Then + $i = $i + 1 + $i_temp = Int($CmdLine[$i]) + If $i_temp < 1 Then + $i_temp = 32 + EndIf + $s_Payload = "" + For $j = 1 To $i_temp + $s_Payload = $s_Payload & "z" + Next + EndIf + ElseIf StringLeft($CmdLine[$i], 2) = "-w" Then + If $CmdLine[0] >= ($i + 1) Then + $i = $i + 1 + $i_TimeOut = Int($CmdLine[$i]) + If $i_TimeOut < 1 Then + $i_TimeOut = 4000 + EndIf + ConsoleWrite("Timneout: " & $i_TimeOut & @CRLF) + Else + ConsoleWrite(_ANSI2OEM("Der Wert muss für die Option angegeben werden: -w" & @CRLF)) + Exit 1 + EndIf + Else + $s_TargetHost = $CmdLine[$i] + EndIf +Next + +HotKeySet("^c", "_CTRL_C") + + +TCPStartup() + +$s_IP = TCPNameToIP($s_TargetHost) +$s_DNS = _TCPIpToName($s_IP) +TCPShutdown ( ) + +If $s_IP = "" Then + ConsoleWrite(_ANSI2OEM("pinz konnte Host " & $s_TargetHost & " nicht finden. Überprüfen Sie den Namen, und versuchen Sie es erneut." & @CRLF)) + Exit 1 +EndIf + +ConsoleWrite(@CRLF) +If $s_DNS = "" Then + ConsoleWrite(_ANSI2OEM("pinz wird ausgeführt für " & $s_IP & " mit " & StringLen($s_Payload) & " Bytes Daten:" & @CRLF)) +Else + ConsoleWrite(_ANSI2OEM("pinz wird ausgeführt für " & $s_DNS & " [" & $s_IP & "] mit " & StringLen($s_Payload) & " Bytes Daten:" & @CRLF)) +EndIf + + + +While 1 + If $b_SkipPing = False Then + $i_Packets_Send = $i_Packets_Send + 1 + ;$s_Result = "Antwort von " & $s_IP & ": " + $s_Result = " " & $s_IP & ": " + If $s_IP = "127.0.0.1" Then + $i_PingTime = Ping($s_IP, $i_TimeOut) + Else + $i_PingTime = _PingLikeMicrosoft($s_IP, $i_TimeOut, $s_Payload) + EndIf + ; When the function fails, @error contains extended information: + ; 1 = Host is offline + ; 2 = Host is unreachable + ; 3 = Bad destination + ; 4 = Other errors +;~ MsgBox(0,"",@error & ";" & @extended) + If $i_Error > 0 Then + $a_PingError[0] = _ANSI2OEM(" Zeitüberschreitung (" & $a_PingError[$i_Extended] & ")" ) + If $i_Extended > 0 Then + $s_Result = $s_Result & " " & Chr(195) & " " & $a_PingError[$i_Extended] + Else +;~ $s_Result = $s_Result & " " & Chr(179) & _ANSI2OEM(" Zeitüberschreitung (>") & $i_TimeOut & "ms)" + $s_Result = StringTrimRight($s_Result, 1) + For $i = 1 To (4 - StringLen($i_TimeOut)) + $s_Result = $s_Result & " " + Next + $s_Result = $s_Result & ">" & $i_TimeOut & "ms " & Chr(179) + EndIf + $i_PingTime = 0 + EndIf + If $i_PingTime > $i_TimeOut Then + $i_PingTime = 0 + ;ConsoleWrite("Result: " & $s_Result & @CRLF) + $s_Result = StringTrimRight($s_Result, 1) + For $i = 1 To (4 - StringLen($i_TimeOut)) + $s_Result = $s_Result & " " + Next + $s_Result = $s_Result & ">" & $i_TimeOut & "ms " & Chr(179) + EndIf + If $i_PingTime >= 0 And $i_Error = 0 Then + For $i = 1 To (4 - StringLen($i_PingTime)) + $s_Result = $s_Result & " " + Next + $i_Packets_Receive = $i_Packets_Receive + 1 + If $i_PingTime < $i_PingTimeMax Then + $i_PingTimeMax = $i_PingTime + EndIf + If $i_PingTime > $i_PingTimeMin Then + $i_PingTimeMin = $i_PingTime + EndIf + ;~ $s_Result = $s_Result & $i_PingTime & "ms |" + $s_Result = $s_Result & $i_PingTime & "ms " & Chr(195) + EndIf + ; So, String sollte jetzt genau 8 Zeichen lang sein, bleiben noch 72 für Anzeige + If $i_PingTime < ($i_WindowSizeHorizontal - StringLen($s_Result)) Then + ; Variante 1: Ping ist unter maximalen Fensterbreite + For $i = 1 To ($i_PingTime) + ;~ $s_Result = $s_Result & "-" + ;~ $s_Result = $s_Result & Chr(196) ; Pfeilspitze + ;~ $s_Result = $s_Result & Chr(178) ; grauer Kasten 1 + ;~ $s_Result = $s_Result & Chr(219) ; voller Kasten + $s_Result = $s_Result & Chr(254) ; voller Kasten klein + Next + Else + ; Neue Variante 2: Wir kürzen den Wert auf unter 100! + $i_PercentPingTime = Int(StringRight($i_PingTime, 2)) + If $i_PercentPingTime > ($i_WindowSizeHorizontal - StringLen($s_Result)) Then + ; In Prozente umrechnen im Verhältnis zu den freien Zeichen + $i_PercentPingTime = Int(($i_WindowSizeHorizontal - StringLen($s_Result)) / $i_PercentPingTime * 100) + ; Aus den Prozenten wieder die Anzahl der Zeichen errechnen + $i_PercentPingTime = Int(($i_WindowSizeHorizontal - StringLen($s_Result)) * $i_PercentPingTime / 100) + EndIf + ;~ ConsoleWrite("Breite der Konsole : " & $i_WindowSizeHorizontal & @CRLF) + ;~ ConsoleWrite("Bisherige Länge : " & StringLen($s_Result) & @CRLF) + ;~ ConsoleWrite("Noch freie Zeichen in der Zeile : " & ($i_WindowSizeHorizontal - StringLen($s_Result)) & @CRLF) + ;~ ConsoleWrite("Geplante Zeichen : " & ($i_PercentPingTime - 1) & @CRLF) + ;~ ConsoleWrite("Summe: : " & (StringLen($s_Result) + $i_PercentPingTime) & @CRLF) + + For $i = 1 To ($i_PercentPingTime - 1) + ;~ $s_Result = $s_Result & "-" + ;~ $s_Result = $s_Result & Chr(196) ; Pfeilspitze + ;~ $s_Result = $s_Result & Chr(178) ; grauer Kasten 1 + ;~ $s_Result = $s_Result & Chr(219) ; voller Kasten + $s_Result = $s_Result & Chr(254) ; voller Kasten klein + Next + EndIf + + ;~ If $i_PingTime > $i_LastPingTime Then + ;~ $s_Result = $s_Result & Chr(16) + ;~ ElseIf $i_PingTime = $i_LastPingTime Then + ;~ $s_Result = $s_Result & Chr(16) + ;~ Else + ;~ $s_Result = $s_Result & Chr(16) + ;~ EndIf + + ;~ If $i_PingTime <= 0 Then + ;~ $s_Result = $s_Result & _ANSI2OEM(" Zeitüberschreitung (") & $i_TimeOut & "ms)" + ;~ EndIf + + If ($i_LastPingTime < $i_PingTime) And ($i_LastResultLen = StringLen($s_Result)) Then + $s_Result = $s_Result & Chr(254) + EndIf + If ($i_LastPingTime > $i_PingTime) And ($i_LastResultLen = StringLen($s_Result)) Then + $s_Result = StringTrimRight($s_Result, 1) + EndIf + + + ConsoleWrite($s_Result & @CRLF) + $i_LastResultLen = StringLen($s_Result) + + EndIf + ; Sleep($i_Pause) + + $i_LastPingTime = $i_PingTime + + If $b_SkipPing = False Then + $i_timer = TimerInit() + $b_SkipPing = True + EndIf + If $b_SkipPing = True Then + If TimerDiff($i_timer) > $i_Pause Then +;~ ConsoleWrite(TimerDiff($i_timer) & "ms" & @CRLF) + $b_SkipPing = False + If $b_EndlessPing = False Then + $i_Counter = $i_Counter + 1 + If $i_Counter >= $i_n Then + ExitLoop + EndIf + EndIf + Else + Sleep(100) + EndIf + EndIf +WEnd + +_WriteStatistics() +Exit $i_Error diff --git a/pinz.exe b/pinz.exe new file mode 100644 index 0000000..a254689 Binary files /dev/null and b/pinz.exe differ