In Microsoft.SharePoint.Publishing.WebControls.ConsoleUtilities class you can see this line of code
internal static string GetUserPawnMarkup(string sipAddress, string suffix)
{
return("<span><img border=\"0\" height=\"12\" src=\"/_layouts/images/imnhdr.gif\" onload=\"IMNRC('" + SPHttpUtility.EcmaScriptStringLiteralEncode(sipAddress) + "')\" ShowOfflinePawn=\"1\" alt=\"\" id=\"MWP_pawn_" + suffix +"\"/></span>");
}
And this is the code used for showing user presence icon in SharePoint site/library/list/item
If you want to have this on your custom .aspx page or web part, you can do it simply by change "sipAdress" with user email address.
<!-- custom .aspx page -->
<%
string userEmail = "james.tsai@local.com";
this.Response.Write("<span><img border=\"0\" height=\"12\" src=\"/_layouts/images/imnhdr.gif\" onload=\"IMNRC('" + userEmail+ "')\" ShowOfflinePawn=\"1\" alt=\"\" id=\"user_presence_icon\"/></span>");
%>
And of course, To get this icon actually working (turn green when user is on) you must have Microsoft Office Communicator installed on client machine.