#!/usr/bin/env python2
"""A basic exploit example.

Input:
    An IP address as first argument:
Output:
    A string composed of the service name, target IP
    address, flag and a timestamp in the following format:
    $service|$ip|$flag|$timestamp"""
import random
import string
import sys
import time
service = 'smartgrid'


if len(sys.argv) < 2:
    sys.stderr.write('Please provide an IP/Host as argument.')
    sys.exit(1)

ip = sys.argv[1]


def outputFlag(flag):
    print('{}|{}|{}|{}'.format(service, ip, flag.strip(), int(time.time())))

if __name__ == '__main__':
    try:
        time.sleep(random.randrange(8))
        for i in range(random.randint(1, 10)):
            flag = ''.join(random.choice('0123456789abcdefghijklmnopqrstuvwxyz') for x in range(31))
            flag += '='
            outputFlag(flag)

        sys.exit(0)
    except KeyboardInterrupt:
        sys.exit(0)
    except Exception as e:
        sys.stderr.write(e)
        sys.exit(1)
