Apple has a site used to check the warranty agreement of Apple hardware. You will need your serial number. To obtain that, click on the Apple menu and then click on About this Mac. From there, click on the greyed Version line until you see the Serial Number. You could also click on the More Info… button to see the Serial Number. Once you have the serial number, navigate to: https://selfsolve.apple.com/agreementWarrantyDynamic.do?newid=y. From there, enter the serial number to see the warranty status as can be seen here.
You can also build this type of functionality into scripts or other systems. To do so, just inject the serial number as a sn= in the URL, as follows:
While you could dig further into scripting parsing through the information that you don’t really get from the command line with this URL, some fine individuals in the Apple community have already done so, using a different URL. There’s stuff in both ruby and python available at https://github.com/chilcote/warranty.