I will assume you mean "disc" drive (cd or dvd).

Does it eject randomly when you are not connected to the internet?

Try disconnecting from your modem/network card and reboot your PC (leaving the internet disconnected) and see if it stops the random ejecting.

CD/DVD disc drives will generally refuse to open if they are faulty, but in years of doing computer service I have never seen one keep ejecting due to a faulty drive.

I would say there is most likely a trojan on your computer. One of the most popular gags built into older trojans was the ability to eject the CD/DVD drive on an infected machine.

If you disconnect from the internet and it still ejects randomly, it could be a piece of software glitching (driver, dvd software, etc) telling the drive that you told it to eject when you didn't, but I would say it's most likely to be a trojan.

The above statement is based solely on my years of doing onsite commercial and residential computer repair. It could be something entirely different, but this gives you something to try.

Rick