Simple Port Checking Tool – AutoIT

Below you will find some code to make a simple port checking tool in AutoIT. The tools simply asks the user for what IP address or Hostname they want to check, and what port. It will then confirm your entry and show you the result.


; Script Function:
; Check if a port is open on a machine and report back to the user

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

; Run port check

UserPort ()

Func UserPort ()

; Ask user for what Port and server they want
Global $Server = InputBox(“Server Hostname / IP”, “What is the Hostname or the IP of the server?”, “”, “”, – 1, -1, 0, 0)
Global $Port = InputBox(“Port”, “What port would you like to check?”, “25”, “”, – 1, -1, 0, 0)

; Display their answer
MsgBox($MB_SYSTEMMODAL, “Responses:”, “I will check ” & $Server & “:” & $Port)


Func CheckPort ()

TCPStartup() ; Start the TCP service.

; Register OnAutoItExit to be called when the script is closed.

; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified.
Local $iSocket = TCPConnect($Server, $Port)

; If an error occurred display the error code and return False.
If @error Then
; The server is probably offline/port is not opened on the server.
Local $iError = @error
MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), “”, “Could not connect, Error code: ” & $iError)
Return False
MsgBox($MB_SYSTEMMODAL, “”, “Connection successful”)

; Close the socket.

Func OnAutoItExit()

TCPShutdown() ; Close the TCP service.


Leave a Reply

Your email address will not be published. Required fields are marked *