Skip to content

Commit

Permalink
Switch connect_ex result checks to use errno lookups (#289)
Browse files Browse the repository at this point in the history
* Switch connect_ex result checks to errno lookups

* Return errno strings, clean up comment
  • Loading branch information
drewmnoel authored Aug 26, 2024
1 parent a6f02ae commit 7752023
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ssh_audit/dheat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import errno
import multiprocessing
import os
import queue
Expand Down Expand Up @@ -442,10 +443,10 @@ def _close_socket(socket_dict: Dict[socket.socket, float], s: socket.socket) ->
# out.d("Creating socket (%u of %u already exist)..." % (len(socket_dict), concurrent_sockets), write_now=True)
ret = s.connect_ex((target_ip_address, aconf.port))
num_attempted_connections += 1
if ret in [0, 115]: # Check if connection is successful or EINPROGRESS.
if ret in [0, errno.EINPROGRESS]:
socket_dict[s] = now
else:
out.d("connect_ex() returned: %d" % ret, write_now=True)
out.d("connect_ex() returned: %s (%d)" % (os.strerror(ret), ret), write_now=True)

# out.d("Calling select() on %u sockets..." % len(socket_dict), write_now=True)
socket_list: List[socket.socket] = [*socket_dict] # Get a list of sockets from the dictionary.
Expand Down

0 comments on commit 7752023

Please sign in to comment.