I'm searching for a method to determine if a pc (whose IP address I know) is or not in LAN connection with mine. I've tried asking subnet mask of both and comparing each bit of IP addresses, but I'm asking if there's a better and more direct way to do that. Sorry for my bad english :S
It's hard to get a good answer if you're not defining the problem clearly: how do YOU tell if they're in the same LAN? Same switch, same subnet, same physical building?
Checking subnet should do the trick for most situations.
Other approach (if the two PCs have been "talking" to each other) is to check out ARP table to see if the IP is there:
arp -a from command prompt. This means you have Layer 2 connectivity with it.