This should be moved inside the loop because otherwise s.connect_ex returns EINPROGRESS (22) error for 2nd, 3rd, etc calls even if port is UP