Skip to main content
Question

Enrollment - naming standard based on IP location

  • March 17, 2020
  • 3 replies
  • 20 views

Forum|alt.badge.img+10

So when enrolling a mac, I would like it to be automatically named based on which country it is enrolled in

So Mac should first lookup like

curl https://freegeoip.app/xml/

and based on country code the mac should be named like "US-%serialnumber%

Serial number can be found serialNumber=$( ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}' )

I am not very good scripting, so hope someone can have some input how this could be done

3 replies

Forum|alt.badge.img+8

Interesting - But my script knowledge not that good. Maybe someone else inhere can help, would also be interested in this setup


Forum|alt.badge.img+10
  • Author
  • Contributor
  • May 4, 2020

Anyone ?


DBrowning
Forum|alt.badge.img+25
  • Esteemed Contributor
  • May 4, 2020

@jameson Give this a shot.

#!/bin/sh

getCountryCode=$(curl https://freegeoip.app/xml/ | xpath /Response/CountryCode)
countryCode=$(echo $getCountryCode | sed 's/<CountryCode>//g' | sed 's/</CountryCode>/'$'
/g')

echo $countryCode

serialNumber=$( ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}' )

computerName=$countryCode-$serialNumber

echo $computerName

networksetup -setcomputername "$computerName"
scutil --set LocalHostName "$computerName"
scutil --set HostName "$computerName"
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName "$computerName"