Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Simple Python MultiTool Indentation error

My python script has an unexpected unindent, i have tried reformatting everything and it still wont work. Please help!
Code
import os
import socket
import subprocess
import sys
from datetime import datetime
global x
x = 1
def main():
    global x
    print("\n\n\n1.) Port Scanner\n2.) Banner Grab\n3.) Ping\n4.) Exit")
    choice = int(input("Pick an option (1-4):  "))
    if choice == 1:
        portScanner()
    elif choice == 2:
        sshBannerGrab()
    elif choice == 3:
        Ping()
    elif choice == 4:
        x = 0
    else:
        print('Invalid Choice!')

def portScanner():
    #Clear Screen
    subprocess.call('clear', shell=True)
    
    #Ask for input
    remoteServer = input("Remote host: ")
    remoteServerIP = socket.gethostbyname(remoteServer)
    
    #Print banner with info on host
    print("-" * 60)
    print("Please wait, scanning remote host", remoteServerIP)
    print("-" * 60)
    
    #Check time started
    t1 = datetime.now()
    
    #Use range to specify ports
    #Also catch errors
    try:
        for port in range(1,10000):
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            result = sock.connect_ex((remoteServer, port))
            if result == 0:
                print("Port {}:     Open".format(port))
            sock.close()
    except KeyboardInterrupt:
        print("You pressed CTRL+C")
        sys.exit()
    except socket.gaierror:
        print("Hostname could not be resolved. Exiting")
        sys.exit()
    except socket.error:
        print("Couldnt Connect to Server")
        sys.exit()
    #Check time again
    t2 = datetime.now()
    
    #Calculate dif in time
    total = t2 - t1
    
    #Print Results
    print('Scanning completed in: ', total)

def bannerGrab():
    targetHost = input("Server: ")
    targetPort = input("Port: ")
    try:
        sock.connect((targetHost, targetPort))
        print('[+] Connection to ' + targetHost + ' port ' + str(targetPort) + ' Succeeded!')
        grab(sock)

def Ping():
    target = input("Target: ")
    response = os.system("ping -c 1 " + target)
    
    if response == 0:
        print(target, 'is up!')
    else:
        print(target, 'is down!')

def grab(sock):
    try:
        sock.send('Grab banner \r\n')
        ret = sock.recv(1024)
        print('[+]' + str(ret))
        return
    except Exception:
        print('[-] Unable to grab banner: ' + str(e))
        return

while x == 1:
    main()
Here's the error:
Code
#...
    try:
        sock.connect((targetHost, targetPort))
        print('[+] Connection to ' + targetHost + ' port ' + str(targetPort) + ' Succeeded!')
        grab(sock)

def Ping():
    # ...

You have no except or finally block.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
Thank you so much, I don't know how I didn't notice that

I also seem to get a "an integer is required (got type str)" error on def bannerGrab():


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 630 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[Python] by kone2148Jan 9, 2018 01:43 PM 2 153 Jan 9, 2018 01:43 PM
Last Post: kone2148
[Python] by fogstoneSep 26, 2017 02:36 PM 3 228 Sep 26, 2017 02:36 PM
Last Post: minimalist