Ticki84 Posted March 7, 2014 Share Posted March 7, 2014 Hello everyone, I search how to Ping() an specific port. I use it to get a server status. This work: Ping("servers.com", 5000) But this doesn't work: Ping("servers.com:12345", 5000) If someone could help me, it's would be wonderful. Link to comment Share on other sites More sharing options...
mlukac89 Posted March 7, 2014 Share Posted March 7, 2014 (edited) U see in help file u cant make a port only adress or ip Parameters address/hostname Can be i.e. "www.autoitscript.com" or "87.106.244.38". timeout [optional] Is the time to wait for an answer in milliseconds (default is 4000). Try this or use TCP or UDP Edited March 7, 2014 by mlukac89 Link to comment Share on other sites More sharing options...
Ticki84 Posted March 7, 2014 Author Share Posted March 7, 2014 (edited) It doesn't work, it always return -1 with default address (from the script) and with the custom adress (from servers). There's the code if you want it: expandcollapse popup#include <File.au3> #include <Misc.au3> Local $Server1 = _PingPort("servers.com", 25001) Local $Server2 = Ping("servers.com", 14050) Local $SServer1 = 0 Local $SServer2 = 0 Func _PingPort($ip, $port) ; Connect to server $nSock = TCPConnect($ip, $port) if ($nSock <= -1) Then return -1 ; Fill up 32 bytes $sBytes = "" For $i = 1 to 32 $sBytes &= " " Next $nTimer = TimerInit() ; Send the 32 bytes to the server $nSent = TCPSend($nSock, $sBytes) if (@error or $nSent <= 0) then Return -1 $nTimerDiff = TimerDiff($nTimer) TCPCloseSocket($nSock) Return $nTimerDiff EndFunc If $Server1 = -1 Then $SServer1 = "close" Else $SServer1 = "open" EndIf If $Server2 = -1 Then $SServer2 = "close" Else $SServer2 = "open" EndIf MsgBox(-1, "Servers Status", "Server 1: " & $SServer1 & @CRLF & "Server 2: " & $SServer2) Edited March 7, 2014 by Ticki84 Link to comment Share on other sites More sharing options...
mlukac89 Posted March 7, 2014 Share Posted March 7, 2014 Here i found this on this forum, try run 1 by 1 UDP expandcollapse popup#include<GUIConstantsEx.au3> $sock = "" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("UDP", 328, 447, 193, 125) $IPin = GUICtrlCreateInput("", 50, 0, 121, 21) GUICtrlCreateLabel("IP/Host:", 0, 0, 50, 17) $History = GUICtrlCreateEdit("", 2, 82, 321, 361) $Go = GUICtrlCreateCheckbox("Start", 250, -2, 75, 25, 0) GUICtrlSetBkColor(-1, 0x009933) GUICtrlCreateLabel("Port", 178, 2, 23, 17) $Portin = GUICtrlCreateInput("", 204, 0, 45, 21) GUICtrlCreateLabel("History", 2, 62, 36, 17) $Gstatus = GUICtrlCreateLabel("", 74, 30, 196, 41) GUICtrlSetFont(-1, 26, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### START Koda GUI section ### Form= UDPStartup() While 1 $msgb = GUIGetMsg() Switch $msgb Case $GUI_EVENT_CLOSE UDPCloseSocket($sock) UDPShutdown() Exit Case BitAND(GUICtrlRead($go),$GUI_CHECKED) Case BitAND(GUICtrlRead($go),$GUI_UNCHECKED) $ip = GUICtrlRead($IPin, 1) $port = GUICtrlRead($Portin, 1) If $ip = "" Or $port = "" Then Else $ip = TCPNameToIP($ip) Sleep(1000) $start = TimerInit() $sock = UDPBind($ip, $port) If @error = 1 Then MsgBox(0, "Error", "Invalid IP entered!") GUICtrlSetState($go, $GUI_UNCHECKED) ElseIf @error = 2 Then MsgBox(0, "Error", "Invalid/closed Port entered!") GUICtrlSetState($go, $GUI_UNCHECKED) ElseIf $sock = -1 Then GUICtrlSetData($Gstatus, "OFFLINE!") GUICtrlSetFont($gstatus, 26) GUICtrlSetColor($gstatus, 0xFF0093) GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] OFFLINE, "&$ip&":"&$port & @CRLF, GUICtrlRead($History)) Else $Stop = Round(TimerDiff($start), 2) GUICtrlSetData($Gstatus, "ONLINE!") GUICtrlSetFont($gstatus, 26) GUICtrlSetColor($gstatus, 0x009933) GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] ONLINE, "&$ip&":"&$port&" ms:" & $Stop & @CRLF, GUICtrlRead($History)) UDPCloseSocket($sock) EndIf EndIf EndSwitch WEnd And TCP expandcollapse popup#include<GUIConstantsEx.au3> $sock = "" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("TCP", 328, 447, 193, 125) $IPin = GUICtrlCreateInput("", 50, 0, 121, 21) GUICtrlCreateLabel("IP/Host:", 0, 0, 50, 17) $History = GUICtrlCreateEdit("", 2, 82, 321, 361) $Go = GUICtrlCreateCheckbox("Start", 250, -2, 75, 25, 0) GUICtrlSetBkColor(-1, 0x009933) GUICtrlCreateLabel("Port", 178, 2, 23, 17) $Portin = GUICtrlCreateInput("", 204, 0, 45, 21) GUICtrlCreateLabel("History", 2, 62, 36, 17) $Gstatus = GUICtrlCreateLabel("", 74, 30, 196, 41) GUICtrlSetFont(-1, 26, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### START Koda GUI section ### Form= TCPStartup() While 1 $msgb = GUIGetMsg() Switch $msgb Case $GUI_EVENT_CLOSE TCPCloseSocket($sock) TCPShutdown() Exit Case BitAND(GUICtrlRead($go),$GUI_CHECKED) Case BitAND(GUICtrlRead($go),$GUI_UNCHECKED) $ip = GUICtrlRead($IPin, 1) $port = GUICtrlRead($Portin, 1) If $ip = "" Or $port = "" Then Else $ip = TCPNameToIP($ip) Sleep(1000) $start = TimerInit() $sock = TCPConnect($ip, $port) If @error = 1 Then MsgBox(0, "Error", "Invalid IP entered!") GUICtrlSetState($go, $GUI_UNCHECKED) ElseIf @error = 2 Then MsgBox(0, "Error", "Invalid/closed Port entered!") GUICtrlSetState($go, $GUI_UNCHECKED) ElseIf $sock = -1 Then GUICtrlSetData($Gstatus, "OFFLINE!") GUICtrlSetFont($gstatus, 26) GUICtrlSetColor($gstatus, 0xFF0093) GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] OFFLINE, "&$ip&":"&$port & @CRLF, GUICtrlRead($History)) Else $Stop = Round(TimerDiff($start), 2) GUICtrlSetData($Gstatus, "ONLINE!") GUICtrlSetFont($gstatus, 26) GUICtrlSetColor($gstatus, 0x009933) GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] ONLINE, "&$ip&":"&$port&" ms:" & $Stop & @CRLF, GUICtrlRead($History)) TCPCloseSocket($sock) EndIf EndIf EndSwitch WEnd LukeLe 1 Link to comment Share on other sites More sharing options...
Ticki84 Posted March 7, 2014 Author Share Posted March 7, 2014 I only need TCP, but is there anyway to not do it 1 by 1 because i have 9 servers ports to test. Link to comment Share on other sites More sharing options...
mlukac89 Posted March 7, 2014 Share Posted March 7, 2014 (edited) It can just script to be adapted to your needs and you need better GUI. It dont be complex to be effective something like this http://prntscr.com/2yp1ca Edited March 7, 2014 by mlukac89 Link to comment Share on other sites More sharing options...
Ticki84 Posted March 7, 2014 Author Share Posted March 7, 2014 I've done something like that and i readapt the script and now it's working fine. Really thanks for all your help guys. Link to comment Share on other sites More sharing options...
mlukac89 Posted March 7, 2014 Share Posted March 7, 2014 Glad to help you Link to comment Share on other sites More sharing options...
LukeLe Posted September 4, 2019 Share Posted September 4, 2019 I made some changes to the TCP source code of @mlukac89 posted above to monitor multiple ports (spacebar delimiter) To monitor multiple ports, just input e.g 80 800 8000 into inputbox expandcollapse popup#include <GUIConstantsEx.au3> #include <StringConstants.au3> $sock = "" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("TCP", 328, 447, 193, 125) $IPin = GUICtrlCreateInput("", 50, 0, 121, 21) GUICtrlCreateLabel("IP/Host:", 0, 0, 50, 17) $History = GUICtrlCreateEdit("", 2, 82, 321, 361) $Go = GUICtrlCreateCheckbox("Start", 250, -2, 75, 25, 0) GUICtrlSetBkColor(-1, 0x009933) GUICtrlCreateLabel("Port", 178, 2, 23, 17) $Portin = GUICtrlCreateInput("", 204, 0, 45, 21) GUICtrlCreateLabel("History", 2, 62, 36, 17) $Gstatus = GUICtrlCreateLabel("", 74, 30, 196, 41) GUICtrlSetFont(-1, 26, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### START Koda GUI section ### Form= TCPStartup() ;118.70.78.54:80 8000 3116 3389 While 1 $msgb = GUIGetMsg() Switch $msgb Case $GUI_EVENT_CLOSE TCPCloseSocket($sock) TCPShutdown() Exit Case BitAND(GUICtrlRead($Go), $GUI_CHECKED) Case BitAND(GUICtrlRead($Go), $GUI_UNCHECKED) $ip = GUICtrlRead($IPin, 1) $port = GUICtrlRead($Portin, 1) If $ip = "" Or $port = "" Then Else $aPort = StringSplit($port, " ", $STR_NOCOUNT) For $p In $aPort PingPort($ip, $p) Next EndIf EndSwitch WEnd Func PingPort($ip, $port) $ip = TCPNameToIP($ip) Sleep(1000) $start = TimerInit() $sock = TCPConnect($ip, $port) If @error = 1 Then MsgBox(0, "Error", "Invalid IP entered!") GUICtrlSetState($Go, $GUI_UNCHECKED) ElseIf @error = 2 Then MsgBox(0, "Error", "Invalid/closed Port entered!") GUICtrlSetState($Go, $GUI_UNCHECKED) ElseIf $sock = -1 Then GUICtrlSetData($Gstatus, "OFFLINE!") GUICtrlSetFont($Gstatus, 26) GUICtrlSetColor($Gstatus, 0xFF0093) GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] OFFLINE, " & $ip & ":" & $port & @CRLF, GUICtrlRead($History)) Else $Stop = Round(TimerDiff($start), 2) GUICtrlSetData($Gstatus, "ONLINE!") GUICtrlSetFont($Gstatus, 26) GUICtrlSetColor($Gstatus, 0x009933) GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] ONLINE, " & $ip & ":" & $port & " ms:" & $Stop & @CRLF, GUICtrlRead($History)) TCPCloseSocket($sock) EndIf EndFunc ;==>PingPort Result is like this FrancescoDiMuro 1 Wondering who uses AutoIT and what it can be used for? Link to comment Share on other sites More sharing options...
SUPPORTTI Posted January 17, 2023 Share Posted January 17, 2023 How do I make it start the application monitoring the ports I need? Example IP: 201.10.30.88 PORT 50000 PORT 50001 PORT 50002 already initializing without having to type in the field Link to comment Share on other sites More sharing options...
spudw2k Posted January 19, 2023 Share Posted January 19, 2023 You could do this a few ways--for example use an external file (e.g. INI) with the details, or simplest would be just to embed the inform into the script. With that route you can just prepopulate the controls with the IP and ports information. Spoiler ;untested $IPin = GUICtrlCreateInput("201.10.30.88", 50, 0, 121, 21) $Portin = GUICtrlCreateInput("50000 50001 50002", 204, 0, 45, 21) Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now