How to Write a Php Licensing Script

Published on December 2016 | Categories: Documents | Downloads: 53 | Comments: 0 | Views: 378
of 3
Download PDF   Embed   Report

Comments

Content

pHow to write a php licensing script
So, I wanted to restrict the usage of my application based on the server’s machine id or network card or harddrive serial number even better the bios serial number. It could be a combination of all of them or just one. Little did I know that php could gather such kind of information without needing a third party software to do that for me. I was well aware that ioncube has the capability to lock the application to run on a server with a certain IP address. Still their solution did not satisfy my needs and once again, curiosity was the motive. I embarked on a course of developing a personal licensing package. I was developing this solution on a windows platform but with a minor tweak can equally ran on other platforms. On windows console, by typing “getmac”, it will list all the mac addresses but you won’t be able to tell which mac address you are currently viewing and when I type “ipconfig /all” I retrieve the mac address as well as their associated cards with a bunch of other network related results. Automatically, this means that I am presented with two solutions: Either I go for the mac address of a specific card on the machine or pick whichever one cames first on the list (blind card). The problem with the second option is that, If you are using a server that has more than one card, lets take my machine for examples has three cards, Bluetooth, wireless and as well as Ethernet card. This means that, for instance if you tracked Bluetooth mac address which on my machine comes up first on each query, this means that whenever the Bluetooth device is turned off, the application will halt cause it will have encountered a different first mac address on the list. This leaves us with one stable solution which is option one, trace a specific but yet reliable card for the mac address on the server (which in often cases, turns out to be the Ethernet card). So I opened my favorite netbeans and started coding in php: Exec(‘ipconfig /all’, $return); Print_r($return); this brings an array of interesting results. On my machine, the following is what I get: Array ( [0] => [1] => Windows IP Configuration [2] => [3] => Host Name . . . . . . . . . . . . : user-PC [4] => Primary Dns Suffix . . . . . . . : [5] => Node Type . . . . . . . . . . . . : Mixed [6] => IP Routing Enabled. . . . . . . . : No [7] => WINS Proxy Enabled. . . . . . . . : No [8] => [9] => Ethernet adapter Bluetooth Network Connection: [10] => [11] => Media State . . . . . . . . . . . : Media disconnected [12] => Connection-specific DNS Suffix . : [13] => Description . . . . . . . . . . . : Bluetooth Device (Personal Area Network) [14] => Physical Address. . . . . . . . . : 00-10-C6-93-57-A0 [15] => DHCP Enabled. . . . . . . . . . . : Yes [16] => Autoconfiguration Enabled . . . . : Yes [17] => [18] => Wireless LAN adapter Wireless Network Connection: [19] => [20] => Media State . . . . . . . . . . . : Media disconnected [21] => Connection-specific DNS Suffix . : [22] => Description . . . . . . . . . . . : Intel(R) PRO/Wireless 2200BG Network Connection [23] => Physical Address. . . . . . . . . : 00-12-F0-AE-7A-AB [24] => DHCP Enabled. . . . . . . . . . . : Yes [25] => Autoconfiguration Enabled . . . . : Yes [26] => [27] => Ethernet adapter Local Area Connection: [28] => [29] => Media State . . . . . . . . . . . : Media disconnected [30] => Connection-specific DNS Suffix . : [31] => Description . . . . . . . . . . . : Broadcom NetXtreme Gigabit Ethernet [32] => Physical Address. . . . . . . . . : 00-14-38-10-81-D8 [33] => DHCP Enabled. . . . . . . . . . . : Yes [34] => Autoconfiguration Enabled . . . . : Yes

[35] => [36] => Tunnel adapter Teredo Tunneling Pseudo-Interface: [37] => [38] => Media State . . . . . . . . . . . : Media disconnected [39] => Connection-specific DNS Suffix . : [40] => Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface [41] => Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0 [42] => DHCP Enabled. . . . . . . . . . . : No [43] => Autoconfiguration Enabled . . . . : Yes [44] => [45] => Tunnel adapter isatap.{1F52A704-0350-4929-9D21-6DCB7F78CC16}: [46] => [47] => Media State . . . . . . . . . . . : Media disconnected [48] => Connection-specific DNS Suffix . : [49] => Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2 [50] => Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0 [51] => DHCP Enabled. . . . . . . . . . . : No [52] => Autoconfiguration Enabled . . . . : Yes [53] => [54] => Tunnel adapter isatap.{60C3BCB8-4111-4BE2-9763-B354FC1C3262}: [55] => [56] => Media State . . . . . . . . . . . : Media disconnected [57] => Connection-specific DNS Suffix . : [58] => Description . . . . . . . . . . . : Microsoft ISATAP Adapter #3 [59] => Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0 [60] => DHCP Enabled. . . . . . . . . . . : No [61] => Autoconfiguration Enabled . . . . : Yes [62] => [63] => Tunnel adapter isatap.{FE6A9EF3-483B-40AB-A27E-066F2341AACE}: [64] => [65] => Media State . . . . . . . . . . . : Media disconnected [66] => Connection-specific DNS Suffix . : [67] => Description . . . . . . . . . . . : Microsoft ISATAP Adapter #4 [68] => Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0 [69] => DHCP Enabled. . . . . . . . . . . : No [70] => Autoconfiguration Enabled . . . . : Yes )

So, based on the results above, you can see that I have a wireless card, Bluetooth as well as an Ethernet card. My interest is the Ethernet card since almost all machines come with one such onboard card. This means that from the result listed above, I will need to extract the Ethernet details. The following is the code that I run in order to extract the ethernet details: $found=NULL; $plus=NULL; foreach ($output as $line) { //check if this the line reads as Ethernet adaptor if ($line == 'Ethernet adapter Local Area Connection:') $fountd= true; if ($found) { if (stristr($line, 'Physical Address')) { $plus = $line; $fount = false; } } } $mac = str_replace("Physical Address. . . . . . . . . :", '', $plus); $mac = implode('', explode('-', $mac));

Code description I declare two variables, $found, $line and instantly set them to null; then I iterate through the results. First, I check for the array with the message: Ethernet adapter Local Area Connection. Once I encounter that line, I set $found to true and continue with my iteration. One important thing to note is that each card declaration has the "Physical Address. . . . . . . . . :" clause before moving on to the next card’s declaration. I then start searching for a line that says Physical Address which comes after the Ethernet

adaptor declaration. This is the line that has the actual mac address. If found, I store it in the $plus variable, set the variable $found to false since the mission is already accomplished. And then I remove the “Physical Address. . . . . . . . . :" . Then the result is a clean mac address which can now be manipulated in various ways to suite your requirements. If you did not care which mac address to use, then you could simply type exec(‘getmac’, $return); Suppose you wanted to use the computer’s serial number, then you would have to use the following code: exec(‘wmic bios get serialnumber’, $return); Note that this solution is system depandant and would not bring up results on windows xp until you provide the administrative credentials. And if you wanted to use the hardrive’s serial number, the following would help exec(‘vol C:’, $return) or even better a combination of bios serial number and harddrive serial number: exec(‘wmic bios get serialnumber && vol C:’,$return)

Conclusion The card specific mac address is a good solution but with the easy of mac spoofing, I would encourage a combination of the hardrive volume number and mac address but then at the sametime the harddrive volume number can easily be cloned. Therefore, I would suggest leaning on the combination of bios serial number, mac address and harddrive serial number or a combination of common machine unique features. I hope this tutorial helps somebody in someway.

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close