Ping script

Get help with using AutoHotkey and its commands and hotkeys
talon0226
Posts: 1
Joined: 05 Jun 2019, 14:57

Ping script

05 Jun 2019, 15:24

Hello, I am trying to use a script built by a co-worker that works on Windows 7 but has issues on Windows 10. Its for running pings inside command prompt and has a kill command but it will only run a ping once and won't run the kill command. Could someone take a look at this and advise on what needs to be fixed? Thanks.

Code: Select all

;MyPingStart:
#SingleInstance force   ; replaces the old instance automaticallymyUser = %A_UserName% 
#p::
x = 1
;numOfPings = 1

myCLIP := clipboard
myCLIP = %myCLIP%  ; relies on "autotrim" to remove leading/trailing white-space
myCLIP := RegExReplace(myCLIP, "[ ?,#_*|""]")   ;remove special chars
;StringReplace , myCLIP, myCLIP, %A_Space%,,All
StringReplace, myCLIP, myCLIP, `n, , All   ;;remove invisible CR
StringReplace, myCLIP, myCLIP, `r, , All

IPvalidation := CheckIP(myCLIP)
;msgbox IP: %IPvalidation%
if (IPvalidation) {
	;msgbox valid %IPvalidation% IP: %IP%
} else {
	msgbox Please enter valid IP
	return
}



;CIDLEN := StrLen(clipboard)
CLIPLEN := StrLen(myCLIP)
if (CLIPLEN > 8 && CLIPLEN < 49)
{
   run, %comspec% /k color 8 & ping -t %myCLIP%, ,     
   WinWait, ping  -t %myCLIP%
   ;WinMove, 0, 0, , , 600, 400
   x := numOfPings*525
   
   ;msgbox  numofpings: %numOfPings% x: %x%
   WinMove, , ,x, 890, 520, 195          ;height=850  title/text/x/y/width/height
   ;Winmove,Editor,,,,150,150
   numOfPings++
   ;msgbox after increment pings: %numOfPings% x: %x%
} else {
	msgbox requires IP address in clipboard
}
return

;MyKillPingStart:
#w::
processes=cmd.exe,ping.exe
Loop, parse, processes, `,   ;an escaped comma  divide the string based on every occurrence of a comma
{
	Loop
	{
		Process, Close, %A_LoopField%
		Process, Exist, %A_LoopField%
	}	Until	!ErrorLevel
}
numOfPings = 0
return






CheckIP(IP)
{
	pos = 1
	While pos := RegExMatch(IP, "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", match, pos+StrLen(match)) 
		return 1
	
	pos = 1
	While pos := RegExMatch(IP, "([a-fA-F0-9]{0,4}:){7,7}[a-fA-F0-9]{0,4}", match, pos+StrLen(match))            ;([a-fA-F0-9]{0,4}:){7,7}[a-fA-F0-9]{0,4}
		return 2
	
	If (IP = "") 
	{
		return 0
	}
	return 0   ;failed
}




/*
msgbox w: numofPings: %numOfPings% 
while numOfPings > 0
{
   Process, Exist, ping.exe
   If (ErrorLevel <> 0) {
		Process, Close, cmd.exe
		Process, Close, ping.exe
		 
		 ;msgbox w: numofPings: %numOfPings% 
   } Else {
        ;msgbox ping winder not found 
   }
   numOfPings--
  
}
Return
*/
[Mod edit: [code][/code] tags added]
User avatar
YoucefHam
Posts: 344
Joined: 24 Aug 2015, 12:56
Facebook: https://fb.me/YoucefHamDz
Google: [email protected]
GitHub: YoucefHam
Location: Algeria
Contact:

Re: Ping script

10 Jun 2019, 20:39

try this

Code: Select all

oldClip := ClipboardAll
ClipWait, 2
Clipboard := ""
url := "www.google.com"
Run, %ComSpec% /c "ping %url% | clip",,Hide,PingID
Process, WaitClose, %PingID%
txt := Clipboard
Clipboard := oldClip
ClipWait, 2
FoundPos := RegExMatch(txt,"Request timed out.")
if FoundPos
{
	MsgBox, Request timed out.
	ExitApp
}
else
{
	FoundPos := RegExMatch(txt,"Ping request could not find host")
	if FoundPos
	{
		MsgBox, Request timed out.
		ExitApp
	}
	else
	{
		FoundPos := RegExMatch(txt,"Reply from")
		if FoundPos
		{
			RegExMatch(txt, "Pinging (.*?) ", Url)
			RegExMatch(txt, "Ping statistics for (.*?):", Ip)
			RegExMatch(txt, "(Minimum = .*?), (Maximum = .*?), (Average = .*?$)", triptimes)
txt =
(
Pinging: %Url1%
IP: %Ip1%
trip times:
%triptimes1%
%triptimes2%
%triptimes3%
)
			MsgBox, % txt
				ExitApp
		}
	}
}
ExitApp
:wave: There is always more than one way to solve a problem. ;)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Eik, Google [Bot], kingamir022, mikeyww and 22 guests