困惑于“threading.BoundedSemaphore”在这个特定的纸条中的角色是什么

2024-09-29 21:43:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我很难理解“Bounded.Semaphore”在这个特定代码中的作用。我在YT上找了一些例子和视频,没有任何帮助。 下面是完整的代码:https://github.com/tatmush/violentPython3/blob/master/Chapter-2/3-sshBrute.py

maxConnections = 5

connectionLock = BoundedSemaphore(value=maxConnections)
try:
    s=pxssh.pxssh()
    s.login(host, user, password)
    print('[+]Password Found: ' + password)
    found=True
    print('Found in CONNECT: {}'.format(found))
except Exception as e:
    print(e)
    if 'read_nonblocking' in str(e):
        logging.debug('Now in if statement')
        fails+=1
        time.sleep(5)
        connect(host, user, password, False)

    elif 'synchronize with original prompt' in str(e):
        logging.debug('Now in elif')
        time.sleep(1)
        connect(host, user, password, False)
finally:
    if release: connectionLock.release()

Tags: 代码indebughostifloggingpasswordprint

热门问题