意外的unindent python

时间:2014-05-03 14:00:20

标签: python

下面的代码真的很烦我,我已经看过stackoverflow和谷歌但还没有找到任何东西,我是一个非常好的python程序员,还没有到目前为止,发现一个我无法处理的错误。

我已尝试过所有内容,但这段代码正在给我

IndentationError: unexpected unindent 

这很奇怪,因为正常的错误是“未检查到的缩进”,这意味着多次发布它的间距以及我如何间隔它所以我经历了整个代码和nada相同的错误,我正确地放入四个空格和一切依然没有。帮助

该脚本出于安全原因和webapp。

#!/usr/bin/python

#!/usr/bin/python
#Greets:SEC4EVER Members.
import hashlib
import base64
import socket
print"""

___  ___ _    _____ _____
|  \/  || |  |_   _|_   _|
| .  . || |    | |   | |
| |\/| || |    | |   | |
| |  | || |____| |  _| |_
\_|  |_/\_____/\_/  \___/
v0.1
"""


def main():
 print '1 - SHA1  Decrypter'; print
print '2 - MD5  Decrypter'
print '3 - Base64 Decrypter'
print '4 - /etc/passwd users extractor'
print '5 - Port Scanner'
elect = input("Select :")

if select==1:
      sha1()
elif select==2:
      md5()
elif select==3:
      base64()
elif select==4:
      extr()
elif select==5:
      scanner()


def   sha1():
    try:
        sha1 = raw_input("\t\n\nSHA1 Hash:")
        dictionary = open("pwds.txt","r")

        for passwd in dictionary.read().split('\n'):
            if hashlib.sha1(passwd).hexdigest() == sha1:

                print("\n\t[OK]"+sha1+" : "+passwd+"\n")


        else:
            print "\n\tFailed; Password not found in dictionary"
            sha1()
    except(IOError):
        print "pwds.txt not found!"
main()
def md5():
    try:
        md5 = raw_input("\t\n\nMD5 Hash:")
        dictionary = open("pwds.txt","r")
        for passwd in dictionary.read().split('\n'):
            if hashlib.md5(passwd).hexdigest() == md5:
                print("\n\t[OK]"+md5+" : "+passwd+"\n")


        else:
            print "\n\tFailed; Password not found in dictionary"
            main()
    except(IOError):
        print "pwds.txt not found!"

def base64():
    try:
     code = raw_input('\n\nBase64:\n\n')
     deco = base64.b64decode(code)
     print '\nDecoded!:\n\n',deco,'\n'
     main()

     def extr():
      try:
       xer = raw_input("/etc/passwd content:")
       passwd_content = xer.split('\n')

       for line in passwd_content :
        y = line.find(':')
       print line[0:y]
       main()

       def scanner():
        try:
         sec4 =raw_input('IP Address:')
         for port in range(1,400):
          s0ck = socket.socket()
         s0ck.settimeout(0.5)
         ip = sec4
         response = s0ck.connect_ex((ip, port))
         if response:
          print ("%d\tclose" %port)
         else:
          print ("%d\topen" %port)
         s0ck.close()

if __name__ !== '__main__': main()

2 个答案:

答案 0 :(得分:5)

base64()功能中,您已打开多个try/except/finally块,但您没有exceptfinally,只有多个try语句。< / p>

另外,如果您打算继续成为“相当不错的python程序员”,请使用4个空格进行缩进,并尝试遵循PEP8样式指南。

答案 1 :(得分:1)

您的def main()代码的缩进不正确,应该是:

def main():
    print '1 - SHA1  Decrypter'; print
    print '2 - MD5  Decrypter'
    print '3 - Base64 Decrypter'
    print '4 - /etc/passwd users extractor'
    print '5 - Port Scanner'
    elect = input("Select :")

    if select==1:
        sha1()
    elif select==2:
        md5()
    elif select==3:
        base64()
    elif select==4:
        extr()
    elif select==5:
        scanner()

另外,请使用至少 2个空格来缩进代码以帮助实现可读性。

更新您的评论:

在这种情况下,正如@alexce所说,由于try块无法匹配。