Skip to content

Instantly share code, notes, and snippets.

@MiqViq
Last active March 28, 2024 11:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiqViq/3a03d55501198a8d59c9 to your computer and use it in GitHub Desktop.
Save MiqViq/3a03d55501198a8d59c9 to your computer and use it in GitHub Desktop.
This script tries to get warranty information for Apple product. This script has not been tested with all Apple devices, only with Mac computers and some iPhone models.
#!/bin/bash
# check_warranty.sh
#
# This script tries to get warranty information for Apple product
#
# This script has not been tested with all Apple devices, only with Mac computers and some iPhone models
#
# Script accepts a valid serial as argument $1
# If argument $1 is not provided then the serial of current computer is used
#
###
# DISCLAIMER: This script may or may not suit for your purposes, no warranties whatsoever
# Script's functionality may break when Apple decides to change their websites at:
# https://selfsolve.apple.com/wcResults.do
# http://support-sp.apple.com/sp/product?
#
###
# This is based on @glarizza's and @chilcote scripts:¬
# https://github.com/glarizza/scripts/blob/master/ruby/warranty.rb¬
# https://github.com/chilcote/warranty/blob/master/warranty.rb
#
###
# version 2013-03-13 by Mika Viikki (aka MiqViq) 2013-03-13
###
# unregistered response:
# window.location.href='/RegisterProduct.do?productRegister=Y&country=' + 'USA' + '&id='+ 'W86073UNVJ1';
# https://selfsolve.apple.com/RegisterProduct.do?productRegister=Y&country=USA&id=W86073UNVJ1
echo "Running '$(basename $0)'..."
if [ "${1}" == "" ]; then
checkSerial=$(ioreg -l | grep -i 'ioplatformserialnumber' | awk -F'"' '{ print $4 }')
else
checkSerial="${1}"
fi
if [ "" == "${checkSerial}" ]; then
echo "ERROR: could not get serial"
exit 1
elif echo "${checkSerial}" | grep -q "SystemSerialNumb"; then
echo "ERROR: motherboard is not serialized properly"
exit 1
fi
echo "Checking warranty status for serial: '${checkSerial}'..."
# get serial snippet for model
serLength=$(printf "${checkSerial}" | wc -c)
if [ ${serLength} -eq 12 ] ; then
snippet=$(echo "${checkSerial}" | rev | cut -b-4 | rev)
else
snippet=$(echo "${checkSerial}" | rev | cut -b-3 | rev)
fi
# get response html
getResponseBody=$(curl -sS -k -t3 -m6 "https://selfsolve.apple.com/wcResults.do?sn=${checkSerial}&Continue=Continue&cn=&locale=&caller=&num=0" 2>/dev/null)
if [ "" == "${getResponseBody}" ]; then
echo "ERROR: not proper response from Apple!"
exit 1
fi
# check if serial was invalid
if echo "${getResponseBody}" | grep -oqw "invalidserialnumber"; then
echo "ERROR: invalid serial number!"
exit 1
fi
# get model info
getModelInfo=$(curl -sS -k -t3 -m6 "http://support-sp.apple.com/sp/product?cc=${snippet}&?lang=en_US" | awk -F 'configCode>' '{print $2}' | cut -d '<' -f1)
if [ "${getModelInfo}" == "" ]; then
getModelInfo="???"
fi
echo "SERIAL NUMBER: ${checkSerial}"
echo "MODEL INFO: ${getModelInfo}"
# get registration status
getRegistrationStatus=$(echo "${getResponseBody}" | awk '/warrantyPage.setClassAndShow/,/;/' | grep -oqw "'green'" && echo 'Registered')
echo "REGISTRATION STATUS: ${getRegistrationStatus}"
#warrantyPage.setClassAndShow('registration', 'green', 'registration-true');
# get hardware warranty status
getWarrantyStatusHW=$(echo "${getResponseBody}" | awk '/warrantyPage.warrantycheck.displayHWSupportInfo/,/;/' | grep -ow 'Active' || echo 'Expired')
echo "WARRANTY STATUS: ${getWarrantyStatusHW}"
#warrantyPage.warrantycheck.displayHWSupportInfo(true, 'Repairs and Service Coverage: Active', 'Your product is covered for eligible hardware repairs and service under a custom agreement. <br/>For more information about your coverage, please <a href="http://support.apple.com/kb/HE57">contact us</a>.<br/>Estimated Expiration Date: November 5, 2016<br/><a href="http://support.apple.com/kb/he44">Learn about Apple&#039;s coverage information for your product.</a>', 'https://selfsolve.apple.com/GetWarranty.do?sn=${checkSerial}');
# get active warranty info
if [ "Active" == "${getWarrantyStatusHW}" ]; then
getExpirationDate=$(echo "${getResponseBody}" | awk '/warrantyPage.warrantycheck.displayHWSupportInfo/,/;/' | grep -i 'Estimated Expiration Date:' | awk -F 'Date: ' '{print $NF}' | cut -d'<' -f1)
# transform exp. date to ISO 8601 YYYY-MM-DD
iso8601ExpDate=$(perl -e 'use strict; use warnings; use Time::Piece; use POSIX qw(locale_h); setlocale(LC_ALL, "en_US.UTF-8"); my $t = Time::Piece->strptime("$ARGV[0]", "%B %d, %Y"); print $t->strftime("%F\n");' "$getExpirationDate" 2>/dev/null)
if [ ! "" == "${iso8601ExpDate}" ]; then
showExpirationDate=${iso8601ExpDate}
else
showExpirationDate=${getExpirationDate}
fi
echo "WARRANTY EXPIRES ON: ${showExpirationDate}"
getWarrantyType=$(echo "${getResponseBody}" | awk '/warrantyPage.warrantycheck.displayHWSupportInfo/,/;/' | egrep -iow 'custom agreement|applecare protection plan|limited warranty' | perl -pe 's/\w+/\u$&/g')
echo "WARRANTY TYPE: ${getWarrantyType}"
fi
# get telephone support status
getPhoneSupportStatus=$(echo "${getResponseBody}" | awk '/warrantyPage.warrantycheck.displayPHSupportInfo/,/;/' | grep -ow 'Active' || echo 'Expired')
echo "PHONE SUPPORT STATUS: ${getPhoneSupportStatus}"
#warrantyPage.warrantycheck.displayPHSupportInfo( true, 'Telephone Technical Support: Active', 'Your product is eligible for telephone technical support under a custom agreement. <br/>For more information about your coverage, please <a href="http://support.apple.com/kb/HE57">contact us</a>.<br/>Estimated Expiration Date: November 5, 2016', 'https://expresslane.apple.com/GetproductgroupList.do?serialno=${checkSerial}');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment