ENV['COMPUTERNAME'] for Mac?
-
Does Mac have an /etc/hostname file?
-
You can't rely on the existence of environment variables (they are not cross-platform like the SketchUp API and even differ between operating system versions). Take them rather as "hints".
Did you already look through all results of this?
ENV.each{|k,v| puts " #{k}: #{v}" }; nil
In case it's not in
ENV
, I guess OS X has an app for that:
(Just a guess, I don't use that.) -
There is indeed an etc/hostname file, and that's what I want -- how to read that from SU Ruby?
And as for iterating ENV, isn't it a bit quicker to just type ENV ? That seems to work.
--J
-
@honkinberry said:
And as for iterating ENV, isn't it a bit quicker to just type ENV ? That seems to work.
Problem is that setting a bogus environment variable, or setting a valid variable to a bogus temporary setting, is quite easy; .. both with a shell script, and from within Ruby.
I would suggest looking into some sort of encrypted key.. what about SSH ?
-
I'm not so concerned if a user has set the ENV variable to a bogus value in an attempt to circumvent our licensing system. I was hoping for just a 95% solution.
(Key point, why would someone hack a license system for free software???)So I just want to query the machine name on a Mac, secure or not.
If there's a way to do that with SSH, if you could point in the right direction, I'll find out. -
@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