Egreg has provided a way to obtain the page count of a PDF using pdfTeX to extract this information from the PDF itself, but it's worth adding to this why a simple 'core TeX' approach does not work.
You may know that TeX uses
\count0 to provide information about which page is being output, and that this is used for adding page number information to printed pages. However, TeX does not use this to track the 'absolute page from start of document'. You can see that with a short demo file
\count0 10 %
This produces two pages of output, but as I've set the first page as '10' they are listed as pages 10 and 11. TeX writes the value of
\count0 to the log when a page is shipped out (in square brackets), and it shows that as far as TeX is concerned these are indeed pages ten and eleven:
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
entering extended mode
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, friulan, galician, german, ngerman, swissgerman, monogreek, greek, h
ungarian, icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, ma
rathi, oriya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian,
kurmanji, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk,
polish, portuguese, romanian, romansh, russian, sanskrit, serbian, serbianc, s
lovak, slovenian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian,
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
 (./test.aux) )</usr/local/texlive/2012/texmf-dist/fonts/type1/public/amsfo
Output written on test.pdf (2 pages, 22281 bytes).
SyncTeX written on test.synctex.gz.
Transcript written on test.log.
Indeed, it is also possible to have the same page number twice
\count0 1 %
\count0 is only reliable if you can be certain that nothing has messed about with it, which in general is not the case.