iTerm2 has a variable $TERM_SESSION_ID which looks like this:
% echo $TERM_SESSION_ID
w1t0p0:C2EA7462-6ED9-479B-A323-5796ABCCABE8
From what I can figure out:
"w1" is the window number (but 0-indexed - so 0==1, 1==2, etc)
"t0" is the tab within the window
I didn't investigate "p0" but I presume something like process?