您的位置:首页 > 理论基础 > 计算机网络

Exporting Information From iPhone Configuration Utility(from http://krypted.com)

2012-05-21 09:47 579 查看
In a previous post I looked at
automatingiPhone and iPad deployment. There, we looked at the iPhoneConfiguration Utility. Now that Profile Manager is built into MacOS X Server in Lion, and with the number of 3rd party MDM solutionson the market, many users of iPhone Configuration Utility
arelooking to extract information from it and move it into otherplaces. Many of these places can import property lists.

If you look at the file header for .mobileconfig and .deviceinfofiles you’ll notice that they begin with the familiar:

<?xml version="1.0"encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plistversion="1.0"><dict>


Given that .mobileconfig and .deviceinfo files are propertylists with different extensions, if you want to turn them intoproperty lists, simply rename them. Given that many people willhave 100s or 1000s of devices, this is something that most willwant to
automate. So, let’s use a basic for loop to do so. Thefollowing will convert .mobileconfig files into plist:

for x in ~/Library/MobileDevice/Configuration\Profiles/*.mobileconfig; do mv $x `basename $x.mobileconfig`.plist; done;


This will put them back:

for xin ~/Library/MobileDevice/Configuration\Profiles/*.plist; do mv $x `basename $x .plist`.mobileconfig;done;


Or to convert the device information to property lists:

for x in ~/Library/MobileDevice/Devices/*.deviceinfo; domv $x `basename $x .deviceinfo`.plist; done;


Or property lists to device information:

for x in ~/Library/MobileDevice/Devices/*.plist; do mv $x`basename $x .plist`.deviceinfo; done;


Once files are converted then you can also automate crawlingthrough them to obtain information. For example, to pull theinformation from the two fields in iPhone Configuration Utilitythat are user editable, ownerName and ownerEmail as well as theserial number
of a device with a deviceIdentifierof 26c2d1b2a68c7862bd4c6bfbe708517964733cf3:

defaults read~/Library/MobileDevice/Devices/26c2d1b2a68c7862bd4c6bfbe708517964733cf3ownerEmail


defaults read~/Library/MobileDevice/Devices/26c2d1b2a68c7862bd4c6bfbe708517964733cf3ownerName


You could then redirect this output into a csv file, perhapsgrabbing other information such as:

UniqueChipID
deviceActivationState
deviceBluetoothMACAddress
deviceBuildVersion
deviceCapacityKey
deviceClass
deviceIdentifier (also the basename of the file)
deviceLastConnected
deviceName
deviceProductVersion
deviceType
deviceWiFiMACAddress

And then there are 3 arrays that wouldn’t likely look great in acsv, but could easily be brought out automatically:

provisioningProfiles: useful if you are duplicatingprovisioning profile information into an mdm solution
configurationProfiles: useful if you are duplicatingconfiguration profile information from devices into an mdmsolution
applicationDictionaries: great for pulling off what apps arewhere

You can get all of this without moving the files to plist aswell, but in this example I am making an assumption that you willbe importing these devices via plist and so you would be convertingthem anyway. The ability to dump information into a csv forreporting
or other types of imports is ancillary. Having said this,I’ve taken it all and wrapped it into a shell script:

echodeviceIdentifier,deviceSerialNumber,ownerName,ownerEmail,UniqueChipID,deviceActivationState,deviceBluetoothMACAddress,deviceBuildVersion,deviceCapacityKey,deviceClass,deviceLastConnected,deviceName,deviceProductVersion,deviceWiFiMACAddress,deviceType>
~/mydevices.csv

for deviceID in *.deviceinfo; do mv "$deviceID" "`basename"$deviceID" .deviceinfo`.plist";

deviceID=${deviceID%.deviceinfo}

deviceserialnumber=`defaults read~/Library/MobileDevice/Devices/$deviceID deviceSerialNumber`

ownerName=`defaults read ~/Library/MobileDevice/Devices/$deviceIDownerName`

ownerEmail=`defaults read ~/Library/MobileDevice/Devices/$deviceIDownerEmail`

UniqueChipID=`defaults read~/Library/MobileDevice/Devices/$deviceID UniqueChipID`

deviceActivationState=`defaults read~/Library/MobileDevice/Devices/$deviceIDdeviceActivationState`

deviceBluetoothMACAddress=`defaults read~/Library/MobileDevice/Devices/$deviceIDdeviceBluetoothMACAddress`

deviceBuildVersion=`defaults read~/Library/MobileDevice/Devices/$deviceID deviceBuildVersion`

deviceCapacityKey=`defaults read~/Library/MobileDevice/Devices/$deviceID deviceCapacityKey`

deviceClass=`defaults read ~/Library/MobileDevice/Devices/$deviceIDdeviceClass`

deviceLastConnected=`defaults read~/Library/MobileDevice/Devices/$deviceID deviceLastConnected`

deviceName=`defaults read ~/Library/MobileDevice/Devices/$deviceIDdeviceName`

deviceProductVersion=`defaults read~/Library/MobileDevice/Devices/$deviceIDdeviceProductVersion`

deviceType=`defaults read ~/Library/MobileDevice/Devices/$deviceIDdeviceType`

deviceWiFiMACAddress=`defaults read~/Library/MobileDevice/Devices/$deviceIDdeviceWiFiMACAddress`

echo$deviceID,$deviceserialnumber,$ownerName,$ownerEmail,$UniqueChipID,$deviceActivationState,$deviceBluetoothMACAddress,$deviceBuildVersion,$deviceCapacityKey,$deviceClass,$deviceLastConnected,$deviceName,$deviceProductVersion,$deviceWiFiMACAddress,$deviceType>>
~/mydevices.csv

done;


This script (which should have a bit more logic put into it fordefining things, etc) should convert all of your .deviceinfo filesto property list while building a csv of their contents (minus thearrays, which I didn’t think prudent to put into csv but whichcould
be thrown in there pretty easily) in ~/mydevices.csv (or mydevices.csv in your home directory). ProfileManager can definitelyimport device holders, which you should be able to do with a coupleof columns of this output…

And to undo the conversion to plist (if you didn’t actually meanto do that part):

for x in ~/Library/MobileDevice/Devices/*.plist; do mv $x`basename $x .plist`.deviceinfo; done;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐