Problem with breaking from a while loop?

This is the place for queries that don't fit in any of the other categories.

Problem with breaking from a while loop?

Postby avivfl » Sat Mar 29, 2014 8:16 am

Code: Select all
print "Welcome to brute forcer"

while True:
    port=int(raw_input("if you want to brut ssl press 1,if browser press 2,  if rdp press 3 \n"))
    if port==1 is True:
        port=443
    break
    elif port==2 is True:
        port=80
        break
    elif port==3 is True:
        port=3389
        break
    else:
        print "you have'nt choosed number between 1-3"




hi guys, i try to loop the in a way that only when port is equal to 1, 2 or 3 he will break, and its not succeed, why?
10x
Last edited by Yoriz on Sat Mar 29, 2014 7:24 pm, edited 2 times in total.
Reason: Initial post lock, CHanged title.
avivfl
 
Posts: 8
Joined: Sat Mar 29, 2014 8:13 am

Re: whie true issue

Postby metulburr » Sat Mar 29, 2014 8:31 am

Code: Select all
    if port==1 is True:
        port=443
    break

I believe you accidentally dedented the break in this line. Indent it inside the if condition. AS it currently stands it will contineu the loop with 1, and break if anything else. You also do not need the
Code: Select all
is True
part as its redundant

Assuming there will be a massive if/elif list, you can use dictionary to accomplish this:
Code: Select all
print "Welcome to brute forcer"

d = {
    1:443,
    2:80,
    3:3389
}

while True:
    user=int(raw_input("if you want to brut ssl press 1,if browser press 2,  if rdp press 3 \n"))
    if d.get(port, None):
        port = d[user]
        break
    else:
        print "you have'nt choosed number between 1-3"
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests