Ultrasound is used in one of two modalities (or both).
Gray-scale ultrasound gives a 2 dimensional image of structures based on relative densities. Sound waves are bounced off of interfaces at which structures of different densities meet, like sonar detecting a submarine underwater.
Doppler ultrasound detects movement (typically blood flow) based on the shift in sound frequency caused by movement (of the red blood cells) dictated by the Doppler principle. It can be used to asses blood flow within the penis and the arteries feeding it and the veins draining it (in the pelvis).
Duplex ultrasound uses both modalities simultaneously.