I want to do like this, please see this for better understandingI have created a small python project and I want to protect it from running multiple devices. I want to add only one device limit. How can I do this? I am about selling the software that's why I am looking for protection tips
this license example you have mentioned is a 128-bit label called uuid.
you can generate them from python:
In [1]: import uuid
In [2]: uuid.uuid4() # uuid v4 just generate a random uuid, not depend on time, mac address, etc....
Out[2]: UUID('61d8aff4-5c4a-4077-b541-54dfed75ce5d')
In [3]: str(uuid.uuid4())
Out[3]: '240f5548-bddd-4a16-b23e-7eafe4bfe0f8'
In [4]: for _ in range(10): # generate 10 uuid
...: print(str(uuid.uuid4()))
...:
e14e27b5-8b52-4ed3-805b-59ef5b0a98fd
c5c5dec3-b0c9-4fe1-9cc8-f30848232813
975d1851-db89-473b-9553-f5b5ff857ee6
a94ab5a7-df71-49e7-9c14-d55c032c4543
00391dca-d148-431e-a9a1-223c0a3058cf
60a4df5d-b838-4c4b-9bb5-19b32432376e
1d38a1e5-d70e-4e56-b1fe-cda7d0e569a0
d5fa9e40-9bd1-479e-affc-45f52ac07caa
bb7c1692-4c29-49ad-9aed-9e755c5d9240
95709582-8a23-4cde-8495-f77ec5dde161
In [5]:
then you need a server to store all license bought by customers. then start a tcp connection to your server, and request for check if license is ok or no. for example (server):
import socketserver
licenses = [
"fcb873d1-6f68-4676-b175-a112cd06288a",
"eaf8625a-bb97-4bcf-a33d-10ef5937a798",
"f3b9d1ea-2b4a-46c5-a82b-0e00b591ae43",
"a3c7d585-cf3e-4595-bae4-147b2e7ccbe8",
"539442ee-4806-44cc-8517-aa3ddd473f38",
"f2d0576f-a9b4-49b6-8cee-db7a75fdd072",
"d750c5e8-5bd1-4345-9ed8-2a9f902f7d8a",
"71404bd2-18b6-45fd-b574-ac0501309166",
"c07b8427-5ed0-47fa-a3e9-9ca1e36009b6",
"7328e718-6aa4-4563-b86a-62fac96ea2d8",
] # some random licenses just for example
class MyTCPHandler(socketserver.BaseRequestHandler):
"""
The request handler class for our server.
It is instantiated once per connection to the server, and must
override the handle() method to implement communication to the
client.
"""
def handle(self):
# self.request is the TCP socket connected to the client
self.data = self.request.recv(1024).strip().decode()
print(f"<{self.client_address[0]}>: request on checking for {self.data}")
if self.data in licenses:
print(f"<{self.client_address[0]}>: {self.data} is valid")
self.request.sendall(b"valid")
else:
print(f"<{self.client_address[0]}>: {self.data} is invalid")
self.request.sendall(b"invalid")
if __name__ == "__main__":
HOST, PORT = "localhost", 9999
# Create the server, binding to localhost on port 9999
server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)
# Activate the server; this will keep running until you
# interrupt the program with Ctrl-C
server.serve_forever()
now all you need is only a tcp client. this is really INSANE for license servers, cuz:
- it got a connection.
- client send a license.
- server response to client.
- connection will close automatically.
but make sure to save license in a file, not in a list.
i recommend to use netcat for debuging your server. for example:
C:\Users\shz2020>nc localhost 9999
fcb873d1-6f68-4676-b175-a112cd06288a
valid -> its from server, not you.
C:\Users\shz2020>
server:
<127.0.0.1>: request on checking for fcb873d1-6f68-4676-b175-a112cd06288a
<127.0.0.1>: fcb873d1-6f68-4676-b175-a112cd06288a is valid
also learn some stuff for encryption, cuz if you just send a plain license text to server, then if a hacker is sniffing the customer connection, license will leak.
i hope i helped you. i will edit and add something if i got any idea.