What can I do to prevent this from happening in the future?
If you are using a personal connection, such as at home, you can run a virus scan on your device to make sure it is not infected with malware.
If you are in an office or on a shared network, you can ask your network administrator to scan the network for improperly configured or infected devices.