Machine ID

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Squirly
Posts: 5
Joined: Tue Aug 08, 2006 10:33 am

Machine ID

Post by Squirly » Wed Nov 29, 2006 11:48 am

I'm trying to get a unique ID number for a machine and so far I've managed to find a function that enables you to get the MAC address of whatever PC you're working on. That's great, except that things change if you go and replace the network card on said machine, making existing code useless. I need a way to identify a PC by it's unique serial number for (cash float purposes) so if anyone has any ideas, I'd appreciate it.

The timer I asked for a couple of weeks ago works beautifully by the way. Thanks.

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: Machine ID

Post by marielle » Wed Nov 29, 2006 1:14 pm

On mac:

Built-in Ethernet, Hardware (MAC) Address
Built-in Firewire, Hardware (MAC) Address
(See system profiler -> Network -> Location. Check out the doc on the apple website but this should different from the airport mac address which can change if you change the network card. If built-in... not supposed to be able to change it. )

Anyway, it looks like this is to work within a networked environment. What about keeping a master file somewhere on a server. On application startup, you check for the existence of a file "unique_id" stored locally. If that file doesn't exist locally, you simply create a new unique id (not yet listed in the master file with all IDs) and store that unique ID locally.

With that solution, you could have your application work in a U3 (movable disk) environment.

Marielle

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: Machine ID

Post by marielle » Wed Nov 29, 2006 1:19 pm

Squirly wrote:I've managed to find a function that enables you to get the MAC address of whatever PC you're working on.
Can you post it here?

Squirly
Posts: 5
Joined: Tue Aug 08, 2006 10:33 am

Post by Squirly » Wed Nov 29, 2006 2:13 pm

I got it from Sons of thunder http://www.sonsothunder.com/devres/revo ... env001.htm

It works, no problem. But the point is that I have to be able to identify a certain machine at any time (it's a touch screen cash register) in order to keep up with the cash float. If you replace the network card of the machine, it obviously gets a new MAC address, making the whole thing kinda useless. Isn't there a machine ID one can use?

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Wed Nov 29, 2006 3:52 pm

Squirly wrote:I got it from Sons of thunder http://www.sonsothunder.com/devres/revo ... env001.htm
Note that this "apple system profiler" is found in older versions. The script above doesn't work on my machine (Mac OS10.4.8 ).

Apple System Profiler 2.1.2 was released on October 21, 1998. This software requires an iMac or PowerPC-based Power Macintosh, PowerBook or Performa computer running North American English Mac OS 7.6, 7.6.1, 8.0, 8.1 or 8.5

To get that info on my system you need this shell call:

Code: Select all

system_profiler SPNetworkDataType|grep -e "MAC Address:"|awk '{print $0}'
The first line is the built-in Ethernet Address, the second line is the built-in firewire address. Tag Names

For older systems, in the script above, you will have to change the part "get Appletalk Address" to something that gives you a unique ID.
Last edited by marielle on Wed Nov 29, 2006 5:31 pm, edited 2 times in total.

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Wed Nov 29, 2006 5:24 pm

Squirly wrote:I have to be able to identify a certain machine at any time (it's a touch screen cash register) in order to keep up with the cash float.
By experience, I know that it is easy to try and force a solution we have in mind into the system. It's often beneficial to take the time to stop and think about what your minimum requirements actually are.

The question that comes to my mind when I take that approach is "do you really need to get some magic number from the system profiler". And the answer I have based on a very incomplete understanding of the problem is no, you don't need to take a risk to have your application not functioning anymore in 1-3 years time because the information you try to read out of the system profiler or the windows equivalent has slightly changed of format.

If all machines are known a priori (rather than have unknown machines connecting), then all you need is on each machine a small file that contains a unique ID that you created whatever way you decided.

If all machines are networked, then you can create this number anytime a new machine connects and store it locally.

Now if the difficulty is about generating a random string while making sure a unique number is given to each machine, here is some code

Code: Select all

on mouseUp
  put field "machineIDs" into tListOfId
  put createrandom(9, tListOfId, 1) & cr after field "machineIDs"
end mouseUp

function createrandom pLength, pList, pCount

    put generateRandomString(pLength) into tRandom
    if tRandom is not among the lines of pList then 
        return tRandom
    end if

    -- If we make it here, this means that the random number 
    -- already exists in the list, let's generate a new one then

    -- Possibility for infinite recursion, have some code to offer 
    -- a graceful exit
    if the shiftkey is down then exit to top
    add 1 to pCount; if pCount > 10 then
        answer "something bad happened"
        exit to top
    end if

    -- Generate a new number
    get createRandom(pLength, pList, pCount)

end createrandom


function generateRandomString pLength
  put empty into tRandom
  repeat with x = 1 to pLength
    put random(10)-1 into tRnd
    -- so that the number never starts with 0
    if x = 1 then put random(9) into tRnd
    put tRnd after tRandom
  end repeat
 return tRandom
end generateRandomString
This was more or less written of the fly, feel free to bring any amendment or correction.

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Wed Nov 29, 2006 11:44 pm

You may have to just physically assign generated ID's to each machine
that your program is installed on.

If you're distributing your program to these machines via the internet...
(Or if the machines are phoning in to download the program...)
You use Rev or something else as a CGI program on a server. Machine
requests it's copy of your program to install. CGI program creates a
unique ID and places it in a text file, then zips up that file along with your
program. Then it sends the zipped file to the machine that requested it.
Now each time that machine runs your program, it grabs it's ID from
that text file and sends the id along with whatever else transaction data
it's sending. Do this for each and every machine that will use your
program.

Well, not sure that'd work for your needs or not, but it's more than
possible to do something like that in Rev. But basing on hardware is
never safe, and just for the reason you already realized.

-Garrett

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Wed Nov 29, 2006 11:45 pm

Gee, I think I basically repeated what marielle already said. Sorry.

-Garrett

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Location: London, UK
Contact:

Post by Mark Smith » Fri Dec 01, 2006 1:08 am

marielle wrote:
Now if the difficulty is about generating a random string while making sure a unique number is given to each machine, here is some code
On OS X, at least, (I don't know if there is something similar on Windows, we have UUID generator in the shell:

get shell("uuidgen")


Best,

Mark

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Mon Dec 04, 2006 12:19 am

Mark Smith wrote:get shell("uuidgen")
I discovered today this illustrated in your stack on the user space:
Rev Online > User Space > Mark Smith > libUUID

Do you see a problem with me adding that stack as well as others (4Panes, AudioWaveForm, Genetic Carpets) to the gallery? You don't have to do anything. I will take a screenshot, reuse the description, make a direct link to the stack within revonline... and send you an email to check that everything is to your liking before making it public.

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Location: London, UK
Contact:

Post by Mark Smith » Tue Apr 17, 2007 12:10 am

marielle wrote:
Mark Smith wrote:get shell("uuidgen")
I discovered today this illustrated in your stack on the user space:
Rev Online > User Space > Mark Smith > libUUID

Do you see a problem with me adding that stack as well as others (4Panes, AudioWaveForm, Genetic Carpets) to the gallery? You don't have to do anything. I will take a screenshot, reuse the description, make a direct link to the stack within revonline... and send you an email to check that everything is to your liking before making it public.
Marielle, sorry I missed this post and never replied. Please feel free to put anything of mine from RevOnline on your site. The more places things can be found, the less likely it is that we have to re-invent the wheel.

Best wishes,

Mark

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Wed Apr 25, 2007 5:15 pm

Mark Smith wrote:Marielle, sorry I missed this post and never replied. Please feel free to put anything of mine from RevOnline on your site. The more places things can be found, the less likely it is that we have to re-invent the wheel.
Great! I was away for a few days... I will update the gallery early next week.

Marielle

Post Reply

Return to “Talking LiveCode”