Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rate Thread Display Modes
Old 07-04-2008, 04:09 AM   #1
aslam
Prospect
 
Join Date: Feb 2007
Location: Vancouver, Canada
Posts: 4
Terminal Command to obtain Local Computer Name (.local)

Does anyone know of a terminal command or Java method/global parameter to determine the local computer name (e.g. my-macbook.local) of an OS X machine?

I need to identify a machine reliably on a regular basis. Thus far we have been using the "hostname" command and that worked fine at first. However we recently realized that this is usually automatically populated by the ISP (via DHCP) with a DNS name (e.g.: xxx-xxx-xxx-xxx.example.com). Now, this works fine for home users because their ISP assigned hostname rarely changes. However with travelling/laptop users this can be a real problem because when they go to another ISP (hotel, airport, client site) their computer gets a new hostname from the local ISP. This breaks our code which is looking for the hostname that the computer had before.

Therefore we need to find an alternative way to reliable identify the same computer, time and time again. I recently realized that there is an OS X machine name which is set in System Preferences -> Sharing -> Edit. It typically looks something like "my-macbook.local". So I thought if I can find out the terminal command to report that, I can suggest our programmers use that variable.

Failing that, does anyone know of a reliable way to identify the same computer, time and time again no matter what internet connection it is on?

Thanks,
Aslam
aslam is offline   Reply With Quote
Old 07-04-2008, 04:33 AM   #2
blb
All Star
 
Join Date: Jan 2002
Location: CO, USA
Posts: 882
Quote:
Originally Posted by aslam
Does anyone know of a terminal command or Java method/global parameter to determine the local computer name (e.g. my-macbook.local) of an OS X machine?

I think scutil may give you this (though you probably have to still append .local):
Code:
scutil --get ComputerName
scutil --get LocalHostName
I'm not sure which one returns the proper information, so try them both.

Quote:
Originally Posted by aslam
...
Failing that, does anyone know of a reliable way to identify the same computer, time and time again no matter what internet connection it is on?

Thanks,
Aslam

You can always ID a system by its MAC address, which you can see from ifconfig, though you'll have to parse it out. Unless there's a better way to query it.
blb is offline   Reply With Quote
Old 07-04-2008, 04:43 AM   #3
baf
MVP
 
Join Date: Jun 2007
Location: Skellefteċ, Sweden
Posts: 1,108
Or you could look at the serial number.
system_profiler SPHardwareDataType |awk -F: '/Serial Number/ {print $NF}'
__________________
/Bengt-Arne Fjellner IT-Administrator Luleċ university, Sweden.
Some say: "You learn as long as you live".
My way: "You live as long as you learn".
baf is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:30 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Site design © Mac Publishing LLC; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of Mac Publishing LLC.