while true issue

while true issue

Postby avivfl » Sun Apr 20, 2014 8:32 am

Code: Select all
import socket
import libssh2


def ssh(username,password):
    global s
    s=libssh2.Session()
    sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("192.168.16.38",22))
    s.startup(sock)
    s.userauth_password(username,password)
    sock.close()


while True:
    try:
        username=raw_input("please enter username")
        password=raw_input("please enter password")
        ssh(username,password)
        print "no cracked"
    except: s.userauth_authenticated()



hi guys, i want that the loop will be ended when i type the right password, instead of it, its keep asking for username and password and stuck after i stop it, why?
avivfl
 
Posts: 8
Joined: Sat Mar 29, 2014 8:13 am

Re: while true issue

Postby Yoriz » Sun Apr 20, 2014 10:28 am

You need to check for a condition that when it is correct you break out of the loop.
Here is an example.
Code: Select all
while True:
    entry = raw_input('enter Y or y to stop')
    if entry.lower() == 'y':
        break
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 993
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: while true issue

Postby avivfl » Sun Apr 20, 2014 12:45 pm

while True:
username=raw_input("please enter username")
password=raw_input("please enter password")
ssh(username,password)
if s.userauth_authenticated() :break
else: continue


i have changed it, if i hit the right code the while is being break, if not, the while stopped and there is error

File "/usr/lib/python2.7/socket.py", line 197, in close
for method in _delegate_methods:
_libssh2.Error: Authentification by password failed.
avivfl
 
Posts: 8
Joined: Sat Mar 29, 2014 8:13 am


Return to Networking

Who is online

Users browsing this forum: No registered users and 2 guests