Hi,
Have you checked your serial port configuration. The Ethernet shield and Arduino Mega might be using the same port in common.
I remember I had to check the serial pinout configuration to avoid problems.
Hope this works.
P.S. Also check the Ethernet shield version.
I think this code was for version 2.