<gh_stars>10-100
#!/usr/bin/python
import sys
import argparse
import serial
import time

def main(argv):
    # mode = 1
    parser = argparse.ArgumentParser(description='Update the C2. Commands (rem, tar) are meant to contain a single MAC address in lowercase format, e.g. 1337af666666.')
    parser.add_argument('-s', "--serialPort",
    help='The serial port to monitor',
    required=True)

    parser.add_argument('-c', "--command",
    help='The command to issue',
    required=False)

    parser.add_argument('-i', "--interactive",
    help='stdin interactive mode',
    required=False,
    action='store_true')

    args = parser.parse_args()
    if not args.command and not args.interactive:
        parser.error('Must supply either/both a command and the interactive switch.')
    # if '-s' in args || '--serialPort'
    serialPort = args.serialPort
    command = args.command
    interactive = args.interactive

    writeCommand(command,serialPort,interactive)


def writeCommand(command, serialPort, interactive):
    try:
        serialCom = openSerial(serialPort)
        if command:
            commToSerial(command, serialCom);
            print 'wrote ' + command + ' to serial port ' + serialPort

        while (interactive):
            time.sleep(0.1)
            command = sys.stdin.readline()
            print 'command is ' + command
            if len(command) > 17:
                print 'command is too long, try again'
                continue
            else:
                commToSerial(command, serialCom)
    except KeyboardInterrupt:
        print '\n KILLED\n'
        serialCom.close()

def openSerial(serialPort):
    serialCom = serial.Serial(serialPort, 115200)
    if serialCom.isOpen():
        serialCom.close()
    serialCom.open()
    return serialCom
    
def commToSerial(command, serialCom):
    # if serialCom.isOpen():
    #     serialCom.close()
    #
    # serialCom.open()
    serialCom.flushInput()
    serialCom.write(command.lower()+'\n')

if __name__ == "__main__":
        main(sys.argv)

        # def send_command(serialPort, command):
        # 	comm = serial.Serial(serialPort, 115200)
        # 	if comm.isOpen():
        # 		comm.close()
        # 	comm.open()
        # 	comm.flushInput()
        # 	comm.write(command+'\n')
        # 	time.sleep(0.1)
        #     return comm.readline()

#!/usr/bin/python
import sys
import argparse
import serial
import time

def main(argv):
    # mode = 1
    parser = argparse.ArgumentParser(description='Update the C2. Commands (rem, tar) are meant to contain a single MAC address in lowercase format, e.g. 1337af666666.')
    parser.add_argument('-s', "--serialPort",
    help='The serial port to monitor',
    required=True)

    parser.add_argument('-c', "--command",
    help='The command to issue',
    required=False)

    parser.add_argument('-i', "--interactive",
    help='stdin interactive mode',
    required=False,
    action='store_true')

    args = parser.parse_args()
    if not args.command and not args.interactive:
        parser.error('Must supply either/both a command and the interactive switch.')
    # if '-s' in args || '--serialPort'
    serialPort = args.serialPort
    command = args.command
    interactive = args.interactive

    writeCommand(command,serialPort,interactive)


def writeCommand(command, serialPort, interactive):
    try:
        serialCom = openSerial(serialPort)
        if command:
            commToSerial(command, serialCom);
            print 'wrote ' + command + ' to serial port ' + serialPort

        while (interactive):
            time.sleep(0.1)
            command = sys.stdin.readline()
            print 'command is ' + command
            if len(command) > 17:
                print 'command is too long, try again'
                continue
            else:
                commToSerial(command, serialCom)
    except KeyboardInterrupt:
        print '\n KILLED\n'
        serialCom.close()

def openSerial(serialPort):
    serialCom = serial.Serial(serialPort, 115200)
    if serialCom.isOpen():
        serialCom.close()
    serialCom.open()
    return serialCom
    
def commToSerial(command, serialCom):
    # if serialCom.isOpen():
    #     serialCom.close()
    #
    # serialCom.open()
    serialCom.flushInput()
    serialCom.write(command.lower()+'\n')

if __name__ == "__main__":
        main(sys.argv)

        # def send_command(serialPort, command):
        # 	comm = serial.Serial(serialPort, 115200)
        # 	if comm.isOpen():
        # 		comm.close()
        # 	comm.open()
        # 	comm.flushInput()
        # 	comm.write(command+'\n')
        # 	time.sleep(0.1)
        #     return comm.readline()
#!/usr/bin/python # mode = 1 # if '-s' in args || '--serialPort' # if serialCom.isOpen(): #     serialCom.close() # # serialCom.open() # def send_command(serialPort, command): # 	comm = serial.Serial(serialPort, 115200) # 	if comm.isOpen(): # 		comm.close() # 	comm.open() # 	comm.flushInput() # 	comm.write(command+'\n') # 	time.sleep(0.1) #     return comm.readline()