How to find out the port state?

I want to check the port state. I know there are plenty Portscanner implementations out there but most of them only assume that a port is open if no error was thrown, otherwise not.

func GetPortState(network string, address string, timeoutInMilliseconds int) {
	timeout := time.Duration(timeoutInMilliseconds) * time.Millisecond

	connection, connectionError := net.DialTimeout(network, address, timeout)

	if connectionError != nil {
		// inspect error

		// return state ...
	}

	defer func() {
		connectionCloseError := connection.Close()

		if connectionCloseError != nil {
			// return error
		}
	}()

	// return state
}

would someone mind helping implementing the function so it’s working correctly?

Thanks in advance

How are you defining an open port?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.