You cannot access your neighbor's code, they have to give it to you. As far as knowing if they are online, if you add them to your address book in My Messages it will show if they are online there. Just know it may not be accurate. Most of us keep the game open even when we're not in front of the computer. So it may show a neighbor online when they are actually away.