Support for Python3

That was fun.
This commit is contained in:
derv82
2018-03-31 23:02:00 -04:00
parent 1ad17472b2
commit 3eddcaa59f
23 changed files with 103 additions and 63 deletions

View File

@@ -63,9 +63,9 @@ class Color(object):
def s(text):
''' Returns colored string '''
output = text
for (key,value) in Color.replacements.iteritems():
for (key,value) in Color.replacements.items():
output = output.replace(key, value)
for (key,value) in Color.colors.iteritems():
for (key,value) in Color.colors.items():
output = output.replace("{%s}" % key, value)
return output
@@ -96,7 +96,7 @@ class Color(object):
if __name__ == '__main__':
Color.pl("{R}Testing{G}One{C}Two{P}Three{W}Done")
print Color.s("{C}Testing{P}String{W}")
print(Color.s("{C}Testing{P}String{W}"))
Color.pl("{+} Good line")
Color.pl("{!} Danger")

View File

@@ -3,6 +3,7 @@
from ..util.process import Process
from ..util.color import Color
from ..util.input import raw_input
from ..config import Configuration
from ..model.result import CrackResult

17
wifite/util/input.py Normal file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
# Fix for raw_input on python3: https://stackoverflow.com/a/7321970
try:
input = raw_input
except NameError:
pass
raw_input = input
try:
range = xrange
except NameError:
pass
xrange = range

View File

@@ -36,6 +36,11 @@ class Process(object):
pid.wait()
(stdout, stderr) = pid.communicate()
# Python 3 compatibility
if type(stdout) is bytes: stdout = stdout.decode('utf-8')
if type(stderr) is bytes: stderr = stderr.decode('utf-8')
if Configuration.verbose > 1 and stdout is not None and stdout.strip() != '':
Color.pe("{P} [stdout] %s{W}" % '\n [stdout] '.join(stdout.strip().split('\n')))
if Configuration.verbose > 1 and stderr is not None and stderr.strip() != '':
@@ -114,6 +119,13 @@ class Process(object):
self.pid.wait()
if self.out is None:
(self.out, self.err) = self.pid.communicate()
if type(self.out) is bytes:
self.out = self.out.decode('utf-8')
if type(self.err) is bytes:
self.err = self.err.decode('utf-8')
return (self.out, self.err)
def poll(self):
@@ -151,7 +163,7 @@ class Process(object):
self.pid.terminate()
break
except OSError, e:
except OSError as e:
if 'No such process' in e.__str__():
return
raise e # process cannot be killed
@@ -159,20 +171,20 @@ class Process(object):
if __name__ == '__main__':
p = Process('ls')
print p.stdout(), p.stderr()
print(p.stdout(), p.stderr())
p.interrupt()
# Calling as list of arguments
(out, err) = Process.call(['ls', '-lah'])
print out, err
print(out, err)
print '\n---------------------\n'
print('\n---------------------\n')
# Calling as string
(out, err) = Process.call('ls -l | head -2')
print out, err
print(out, err)
print '"reaver" exists:', Process.exists('reaver')
print('"reaver" exists:', Process.exists('reaver'))
# Test on never-ending process
p = Process('yes')

View File

@@ -3,6 +3,7 @@
from ..tools.airodump import Airodump
from ..util.color import Color
from ..util.input import raw_input, xrange
from ..model.target import Target
from ..config import Configuration
@@ -40,7 +41,7 @@ class Scanner(object):
try:
self.targets = airodump.get_targets()
except Exception, e:
except Exception as e:
break
if self.found_target():
@@ -219,7 +220,7 @@ if __name__ == '__main__':
try:
s = Scanner()
targets = s.select_targets()
except Exception, e:
except Exception as e:
Color.pl('\r {!} {R}Error{W}: %s' % str(e))
Configuration.exit_gracefully(0)
for t in targets: