Unique Identifier for multiple platforms

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
david.silmanBUSrUeQ
Posts: 44
Joined: Thu Jul 19, 2012 1:49 pm

Unique Identifier for multiple platforms

Post by david.silmanBUSrUeQ » Wed Feb 06, 2013 4:30 pm

I've recently posted a couple of questions, both of which have been answered, but neither really giving me the answer I need;
They can be found here:
Hard Drive Serial Numbers
http://forums.runrev.com/viewtopic.php?f=8&t=14078
And
Mobile MAC Addresses
http://forums.runrev.com/viewtopic.php?f=8&t=14079

What I am really after is a way of uniquely identifying a device across the following platforms:
Windows
Mac
Linux
iOS (iPad)
Android

Is there a way to do this that anyone knows of?
The only remaining solution we can think of is creating a file to store a unique id in a folder separate of the program, so that if the program is copied to another machine, that file would be missing (or if the file was stored with the program it wouldn't match the new machine) and therefore the program wouldn't work, however, we still need a way to generate this file, due to the nature of the program the likelihood of someone trying to steal the program is high, so we really need a way of protecting it.

Thanks all
David

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Unique Identifier for multiple platforms

Post by dunbarx » Wed Feb 06, 2013 4:51 pm

I got an answer to a similar question a while back. Perhaps this might help. It is a shell command to get the serial number of the running machine:

on mouseUp
put last word of shell("system_profiler SPHardwareDataType | grep 'Serial Number'")
end mouseUp

Can this be configured to identify the device? Do serial numbers fall into parsable families, based on device type?

Craig Newman

david.silmanBUSrUeQ
Posts: 44
Joined: Thu Jul 19, 2012 1:49 pm

Re: Unique Identifier for multiple platforms

Post by david.silmanBUSrUeQ » Wed Feb 06, 2013 5:09 pm

That's pretty cool, except the it doesn't return anything useful on windows. I suppose we could use a mixture of Hard Disk serial numbers and machine serial numbers, but I think it'd be better if there was a "one for all" approach?

I'll definitely be keeping this in mind though thanks.

Thanks
David

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Unique Identifier for multiple platforms

Post by Simon » Wed Feb 06, 2013 11:15 pm

Hi David,
To get the MAC address for Windows, Linux and Mac:

Code: Select all

function GetMACAddress
   local retVal
   switch (the platform)
      case "MacOS"
         set the itemDel to "."
         if item 1 of the systemVersion < 10 then
            set the directory to specialFolderPath("apple")
            put "tell application" && quote & "Apple System Profiler" & \
                  quote & cr & "get appletalk address" & cr & "end tell" into getMACScript
            put "tell application" && quote & "Apple System Profiler" & \
                  quote & cr & "close window" && quote & "Apple System Profiler" & quote & \
                  cr & "end tell" into quitASPScript
            do getMACScript as AppleScript
            put the result into retVal
            do quitASPScript as AppleScript
            replace "{" with "" in retVal
            replace "}" with "" in retVal
            replace quote with "" in retVal
         else
            put shell("/sbin/ifconfig en0") into ifConfigs
            if char 1 to 4 of ifConfigs = "zsh:" then
               return "Error retrieving interface configuration."
            else
               get matchText(ifconfigs,"(?s)ether (.*?) ",retVal)  -- These are spaces on either side of (.*?)
               if it is false then
                  return "Error retrieving MAC address."
               end if
            end if
         end if
         break
      case "Win32"
         put (there is a file (specialFolderPath("system") & "/IPCONFIG.EXE")) into winExists
         put (there is a file (specialFolderPath("system") & "/SYSTEM32/IPCONFIG.EXE")) into sys32Exists
         if winExists or sys32Exists then
            set the hideConsoleWindows to true
            put shell("ipconfig /all") into temp
            put lineoffset("Ethernet adapter Local Area Connection:",temp) into tOff
            delete line 1 to (tOff-1) of temp
            get matchText(temp,"Physical Address[\. ]*: ([A-Z0-9-]*)",retVal)
         else
            return "IPCONFIG not found"
         end if
         break
      case "Linux"
         if there is a file("/sbin/ifconfig") then
            put shell("/sbin/ifconfig") into temp
            get matchText(temp,"HWaddr[* ]([0-9A-Za-z:]*)",retVal)
         else
            return "An error has occured."
         end if
         break
   end switch
   return retVal
end GetMACAddress
This isn't mine and I forget where I got it from but it works. It's a bit overkill as ipconfig returns much more unnecessary data then shell("getmac") for Windows. So maybe between system_profiler and getmac you can come up with your own function.

For iPhone look up in the dictionary iphoneSystemIdentifier it will give you the UUID

For Android look up mobileBuildInfo in the dictionary, be careful as the device serial number is not always returned. Maybe you can combine several of the returned values to create a "nearly" unique ID.

Simon
Last edited by Simon on Thu Feb 07, 2013 3:40 am, edited 1 time in total.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Unique Identifier for multiple platforms

Post by jacque » Thu Feb 07, 2013 1:09 am

I needed to do that on Android and it didn't work very well. Neither of my devices returned any useful info. An afternoon with Google showed I wasn't the only one with the problem. Some (most?) devices don't have or don't provide a serial number. Some people thought concantenating all the build info would produce a unique string, but that isn't true either. A lot of the build info comes back as generic, like "unknown" or "Samsung". Everyone with the same model Android device would have the same build info. I haven't found a good way to do it yet. The other OSs have reliable info though.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Unique Identifier for multiple platforms

Post by shaosean » Thu Feb 07, 2013 7:07 am

Using the hard drive serial number and/or the MAC address is not 100% reliable either, as the end user may upgrade their hard drive and/or NIC and then you will have a different SN/MAC..

david.silmanBUSrUeQ
Posts: 44
Joined: Thu Jul 19, 2012 1:49 pm

Re: Unique Identifier for multiple platforms

Post by david.silmanBUSrUeQ » Thu Feb 07, 2013 9:19 am

Wow, thanks for all the replies guys

Some really great ideas there that I'm going to have to try

Thanks for the code Simon, I've used the Sons Of Thunder code to get the mac address before, but couldn't find a way to do it on ipad and android.
(Well, i did find an external for ipad, but nothing for android)
I'll definitely take a look at those 2 functions you posted, they could be promising

I'm starting to think that it might become necessary to go for something unique to the platform and prefix it with the machine type or something, rather than something that is unique and yet present in all devices.

Whilst we know that the user could change the hard drive / network card, we're fairly sure that this won't be much of an issue.

Thanks again to all of you
David

*EDIT*
Could someone give me more information on the different properties in mobileBuildInfo?
I've looked in the dictionary and online, but I'd like a bit more information, specifically:
ID: What is this? It says "Either a change list number, or a label like "M4-rc20"."
How is it created?

FINGERPRINT: What does it mean by the build? Does it mean that it identifies the device? Or the version of os running on the device? Or the version of the app on the device? (Also, if it's the version of os on the device, I'm guessing that all devices with the same version will have the same fingerprint?)

HOST: Is that the machine that built the os version?

As you can see, I think I'm getting myself rather confused about all these, they're probably much simpler than I'm taking them for.
Sorry if it's a dumb question and thanks for your patience and help
David

david.silmanBUSrUeQ
Posts: 44
Joined: Thu Jul 19, 2012 1:49 pm

Re: Unique Identifier for multiple platforms

Post by david.silmanBUSrUeQ » Thu Feb 07, 2013 11:30 am

Actually, disregard my above question, thanks for all your help

We've decided to use the milliseconds, converted to hexadecimal and stored on first run
This way we can have something that is (99.9% of the time) unique and the same across all platforms

Thanks all
David

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: Unique Identifier for multiple platforms

Post by Tester2 » Tue May 14, 2013 9:25 pm

Hey David,

I am looking for a unique ID for my app and came across your thread.

What code did you end up using....you mentioned a milliseconds conversion?

Also, if the user deleted and reinstalled the app would this ID still remain the same or would it create a new one?

Thanks.

david.silmanBUSrUeQ
Posts: 44
Joined: Thu Jul 19, 2012 1:49 pm

Re: Unique Identifier for multiple platforms

Post by david.silmanBUSrUeQ » Wed May 15, 2013 3:24 pm

Hi Tester2

Yes we went with converting the milliseconds into hexadecimal.
We chose this as it's nigh impossible for the app to be run first time on more than one machine at the same moment down to the millisecond and so this offered the best solution for us.
(We were also testing on a rather bad knock off android tablet that didn't know it's own serial number, which made that a redundant method of identifying the device)

Depending on where you stored the code it might be possible for it to remain after the app is deleted, you'd need to look up file locations on whichever mobile platform it is you are after.

Hope this is what you're after
David

Post Reply