loops - python3 port scanner outer variable -


i scanning port range after user set ip in input field in python3. works looks not professional. have loop in while , in there try. how can write more elegant, without outter class break point? thanks.

code looks this:

s = socket.socket()  class outtervar():     connected=0  while(test.outtervar==0):     ip = getfrominputfield()     x in range(100):          try:             s.connect((ip, port + x))             outtervar.connected=1             break         except socket.error e:             print("cannot connect")             print(e)             outtervar.connected=0 

you use function returns on success:

def connect(s):     while true:         ip = getfrominputfield()         x in range(100):              try:                 s.connect((ip, port + x))                 return             except socket.error e:                 print("cannot connect")                 print(e)  s = socket.socket()                 connect(s) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -