Skip to content

Restrict license to specific machine

marcorobiati edited this page Sep 23, 2022 · 3 revisions

As of version 3.2.0


You may want to restrict the use of your software to a certain machine. To do this license3j provides a class HardwareBinder that makes it possible to get a hardware ID. You can encode this ID into the license as a <feature> and when the license is checked you can calculate it again and compare the value to the one that is in the license.

This is more restrictive than just a plain license because it will not allow the user to move the license from one machine to another, and it will also require some means to generate the ID of the machine that he wants the software to run on before the license is created.

This usually means that you have to provide an auxiliary program, that contains license3j and calculates the machine ID. Another approach is to provide the program you want to protect and even without a valid license, it can be used to print out the ID.

The code in HardwareBinder will take all network cards into account except for virtual, loopback and point-to-point ones as well as the architecture of the machine running your program and the hostname.
The "architecture" of the machine is the string returned by the Java API System.getProperty("os.arch")
The "hostname" of the machine is the string returned by the Java API InetAddress.getLocalHost().getHostName()

You can alter the behavior of HardwareBinder:

  • using allowed(String regex) and denied(String regex) methods which only use in the first case, or exclude in the second, network intefaces from the regex provided
  • using the methods of the inner class Ignore, hostName(), network() and architecture() which respectively ignore the hostname, the intework interfaces and the architecture in the calculation.
Clone this wiki locally