ENV['COMPUTERNAME'] for Mac?
-
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
uname -n``? No ssh needed (?). -
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:inread': 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!
hostnamedoes 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!
hostnamedoes 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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement