There is a lot of information you can acquire about the hardware of the computer your program is running on, including serial numbers of individual pieces of hardware (consult stackoverflow for code examples). This gives you a pretty accurate fingerprint of the system.
If you have your software "phone home" by contacting your server at startup, it can send you that fingerprint to tell you which machine it is executed on. If you receive far more such fingerprints than you sold licenses, then something is wrong.
However, this won't tell you from whom the pirate obtained their copy. You could find that out by only distributing personalized copies of your software: Include a serial number in each copy you sell. Send the serial to the server together with the hardware fingerprint. When your server receives the same serial number with a different hardware fingerprint, you know which of your customers pirated it and you can take legal actions.
But there are, of course, countermeasures the pirates could take:
- Find the serial-number in your software and change it to hide the source
- Use a personal firewall to block the phoning-home feature
- When the software won't run without phoning home, crack the software to suppress the phoning-home feature
- Crack the phoning-home feature to send false hardware fingerprints
Unfortunately there is not much you can do about this. Once your software is on hardware you don't control, it's no longer your software.
The software industry is trying to develop software-based copy protection since the invention of the floppy disk. So far they haven't succeeded in creating a solution which withstood serious cracking attempts from the piracy community, despite investing millions of dollar and using some ethically questionable methods (like modifying the users operating system).
I am also a software developer and I have come to the realization that there are really only two ways to make money with consumer software:
Method 1: Tie your software closely to a subscription-based online service. Consider the service your actual product and the client software a free tool to use it.
Method 2: Simply accept that only those people who really want to pay for your software will pay for it and the rest of the world will pirate it.