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()

