The most direct way is by measuring the orbit distance and period of an orbiting satellite. By Newtonian mechanics, the period and distance are very simply related to the mass of the primary body via:
1 2 G M --- V = ------- 2 Rwhere the velocity of the satellite is just V = 2 pi R / T where T is the period and R is the distance to the center of the planet. Some planets such as Mercury and Venus do not have satellites so you may send one there yourself as NASA has done and measure how the planet perturbs the trajectory of a passing man-made satellite. The idea is the same. You can also get a fair approximation by knowing the size of the planet and assuming a typical density for its composition.