ENV['COMPUTERNAME'] for Mac?
-
@honkinberry said:
(Key point, why would someone hack a license system for free software???)
Your OP said nothing about it being free.
I would counter, why would you want to complicate free software with a license management system ?
Why would users want the hassle ?
-
So why don't you query it simply with
-
from Ruby Console
`ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { printf; }' `
returns
"IOPlatformUUID" = "00000000-0000-1000-8000-001E••••••••"
I believe this is reasonably robust and unique...
the ••••• are just me masking mine.
johnedit to add from the man page...
DESCRIPTION
ioreg displays the I/O Kit registry. It shows the heirarchical registry
structure as an inverted tree. The provider-client relationships among
those objects is shown as follows:+-o provider | +-o client By default, object properties are not shown. The use of the -c, -k, -l, or -n options cause ioreg to show properties for objects that match the specified criteria.
-
@honkinberry said:
There is indeed an etc/hostname file, and that's what I want -- how to read that from SU Ruby?
--J
Just read it.
hostname = File.read('/etc/hostname').strip
-
@jim said:
Does Mac have an /etc/hostname file?
only if someone/or some code has added it already...
Error: #<Errno::ENOENT: (eval):2:in
read': No such file or directory - /etc/hostname>`
in /etc/ I have
hostconfig
hosts
hosts.equiv
but none contain any 'unique-ness' identifiers.
john -
driven is correct, no such filename.
I was incorrect, I did a "cd /etc" and then typed "hostname", like an idiot. Sorry.the ioreg is interesting, but when I try that from Ruby console I get undefined local variable or method.
I appreciate everybody's help.
To emphasize, I was looking for something quick and easy, along the lines of the ENV vars.
If SU doesn't have that on the Mac side, I can add a config.rb faster than any other solution.
It sure would be nice to have, hint hint!!!--J
-
@honkinberry said:
the ioreg is interesting, but when I try that from Ruby console I get undefined local variable or method.
try without the awk filtering
theLot=(`ioreg -rd1 -c IOPlatformExpertDevice 2>&1` )
should give a proper error if not the return...
then sort from the return what you want...
{ "compatible" = <"iMac7,1"> "version" = <"1.0"> "board-id" = <"Mac-F42386C8"> "IOInterruptSpecifiers" = (*********************long number hidden by me*************************) "IOPolledInterface" = "SMCPolledInterface is not serializable" "serial-number" = <*********************long number hidden by me*************************> "IOInterruptControllers" = ("io-apic-0") "IOPlatformUUID" = "*********************long number hidden by me*************************" "IOPlatformArgs" = <*********************long number hidden by me*************************> "clock-frequency" = <0008af2f> "manufacturer" = <"Apple Inc."> "IOConsoleSecurityInterest" = "IOCommand is not serializable" "IOPlatformSerialNumber" = "W8****ditto****T" "system-type" = <01> "product-name" = <"iMac7,1"> "model" = <"iMac7,1"> "name" = <"/"> "IOBusyInterest" = "IOCommand is not serializable" }
remember, not all macs have a serial number
john -
@honkinberry said:
I was incorrect, I did a "cd /etc" and then typed "hostname", like an idiot. Sorry.
You can use that then.
hostname =
hostname.stip
(Works on win 8, but not sure how far back in terms of windows versions the command exists.)
I just assumed unique-ness was not an issue otherwise it would have been part of the original request.
host names and computer names are definitely not unique.
-
Oh, both of these last pasts, bammo, thank you guys!!!!
the ioreg is interesting for sure -- the board-id seems valuable for my purposes.But Jim is correct!
hostname
does indeed work.
So for me at least, it's as easy as:
machinename = ENV['COMPUTERNAME']
if (!machinename) then machinename =hostname
# must be a MacThanks all!!!
-
@honkinberry said:
Jim is correct!
hostname
does indeed work.but that returns the same on all 5 macs on my network, so for a Licence management usage it seems a bit pointless?
If you only need to know if it's a mac or not there are many simple ways to get that...glad your happy
john
Advertisement