Yes, Viking communicated directly with Earth. Not to say others have not, I mention this because I found JPL's very detailed Telecommunications and Data Aquisition Systems Support for the Viking 1975 Mission to Mars. Appendices C and D contain a log of all direct contact with the Viking landers.
Most Mars landers these days prefer to relay through a growing network of international spacecraft in orbit around Mars. This saves power, increases bandwidth, and simplifies transmission. The Viking landers also used dedicated relaying orbiters, but they were also capable of transmitting direct to Earth via a high gain S-Band dish.
A stored program in the lander turned a transmitter on at a specified time corresponding to each Earth view period, and a long-term stored program maintained the antenna's Earth-pointing direction. The Earth-pointing antenna program was written to be valid through 1994.
This was done using the Deep Space Network, three 70 meter dishes located 120 degrees apart around the world. The same network is used today.
It is quite easy for an US lander to transmit a simple carrier on a stable precise frequency that can be received by big antenna on Earth or in space, a signal whose shift in frequency as seen by the receiver would demonstrate that the US really have working landers on Mars.
Let's clear this up. It is not quite easy.
You gave an example of receiving a signal from the Moon. The Moon is about 400,000 km from the Earth. It is tidal locked to the Earth. It has no atmosphere to interfere with radio communications. Light delay is about 1.5 seconds.
Mars is, depending on the date, between 60,000,000 and 400,000,000 km away from the Earth, 100 to 1,000 times further than the Moon. It rotates relative to the Earth. It has an atmosphere. Light delay is 200 to 1300 seconds making targeting tricky.
It's a lot harder to communicate with Mars than the Moon.