#import the modules
import c4d, string, random
from uuid import getnode as get_mac

secret = '12X'#secret string
mac = get_mac()#get 48 bit mac address
mac3 = str(mac)[-3 :]#get last 3 digits of full 48 bit mac address
mac2 = mac3[: -1]#get first 2 digits of the 3 retrieved previously

#generate some random characters
S1 = 1  # number of characters in the string.
S2 = 4  # number of characters in the string.
ran1 = ''.join(random.choices(string.ascii_letters, k = S1))#grab 1 random character
ran2 = ''.join(random.choices(string.ascii_letters, k = S2))#grab 2 random characters

# format the serial
sn = (str(ran1) + "1" + (mac2) + (secret) + str(ran2))

LBL_INFO = 1001
AUTH_CODE = 1002
BTN_CLOSE = 1003
BTN_COPY = 1004
BTN_HELP = 1005
GROUP_OPTIONS = 1006

class Keygen(c4d.gui.GeDialog):

    def CreateLayout(self):
        self.SetDefaultColor(0, c4d.COLOR_BG, c4d.Vector(.169,.169,.169))
        self.SetTitle("3DtoAll C4D KG")
        self.GroupBegin(GROUP_OPTIONS, c4d.BFH_CENTER, 3, 1)
        self.AddStaticText(LBL_INFO, c4d.BFH_LEFT, name='3DtoAll C4D KG')
        self.GroupEnd()
        self.GroupBegin(GROUP_OPTIONS, c4d.BFH_CENTER, 4, 1)
        self.SetDefaultColor(LBL_INFO, c4d.COLOR_TEXT, c4d.Vector(0,255,255))
        self.AddStaticText(AUTH_CODE, c4d.BFH_SCALEFIT)
        self.SetDefaultColor(AUTH_CODE, c4d.COLOR_TEXT, c4d.Vector(1,1,1))
        self.SetString(AUTH_CODE, sn)
        self.GroupEnd()
        self.GroupBegin(GROUP_OPTIONS, c4d.BFH_CENTER, 4, 1)
        self.AddButton(BTN_HELP, c4d.BFH_SCALE, name='Help')
        self.AddButton(BTN_COPY, c4d.BFH_SCALE, name='Copy')
        self.AddButton(BTN_CLOSE, c4d.BFH_SCALE, name='Close')
        self.GroupEnd()
        return True

    def Command(self, id, bc):
        if id == BTN_HELP:
            c4d.gui.MessageDialog("1.) Press Copy button.\n2.) Paste copied serial into the authorization field of the plugin.\n3.) Buy it if you make money off of it!")
        if id == BTN_COPY:
            c4d.CopyStringToClipboard(sn)
        if id == BTN_CLOSE:
            self.Close()
        return True

def main():
    dlg = Keygen()
    dlg.Open(c4d.DLG_TYPE_MODAL, defaultw=160, defaulth=120)

if __name__ == "__main__":
    main()