sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    ENV['COMPUTERNAME'] for Mac?

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 5 Posters 1.8k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      honkinberry
      last edited by

      Hi all,
      long-time fan, first time posting.

      I was hoping to access ENV['COMPUTERNAME'] to use with our License management system.
      But it seems that value is only available on the PC side. Is there a way to get this on the Mac side?

      Thanks for any assistance!

      --J

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        Does Mac have an /etc/hostname file?

        Hi

        1 Reply Last reply Reply Quote 0
        • A Offline
          Aerilius
          last edited by

          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: uname -n``
          (Just a guess, I don't use that.)

          1 Reply Last reply Reply Quote 0
          • H Offline
            honkinberry
            last edited by

            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

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @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 here much anymore.

              1 Reply Last reply Reply Quote 0
              • H Offline
                honkinberry
                last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @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 ?

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    Aerilius
                    last edited by

                    So why don't you query it simply with uname -n``? No ssh needed (?).

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      driven
                      last edited by

                      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.
                      john

                      edit 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.
                      

                      learn from the mistakes of others, you may not live long enough to make them all yourself...

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Jim
                        last edited by

                        @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

                        Hi

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          driven
                          last edited by

                          @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

                          learn from the mistakes of others, you may not live long enough to make them all yourself...

                          1 Reply Last reply Reply Quote 0
                          • H Offline
                            honkinberry
                            last edited by

                            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

                            1 Reply Last reply Reply Quote 0
                            • D Offline
                              driven
                              last edited by

                              @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

                              learn from the mistakes of others, you may not live long enough to make them all yourself...

                              1 Reply Last reply Reply Quote 0
                              • J Offline
                                Jim
                                last edited by

                                @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.

                                Hi

                                1 Reply Last reply Reply Quote 0
                                • H Offline
                                  honkinberry
                                  last edited by

                                  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 Mac

                                  Thanks all!!!

                                  1 Reply Last reply Reply Quote 0
                                  • D Offline
                                    driven
                                    last edited by

                                    @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

                                    learn from the mistakes of others, you may not live long enough to make them all yourself...

                                    1 Reply Last reply Reply Quote 0
                                    • 1 / 1
                                    • First post
                                      Last post
                                    Buy SketchPlus
                                    Buy SUbD
                                    Buy WrapR
                                    Buy eBook
                                    Buy Modelur
                                    Buy Vertex Tools
                                    Buy SketchCuisine
                                    Buy FormFonts

                                    Advertisement