Scan a Website for Malicious Content and Threats in Python

Cloudmersive
2 min readFeb 18, 2022
URL Virus Scan Response Model (Cloudmersive API Console)

Malicious URLs are a nagging threat in the information security landscape, partially due to our human propensity to foolishly click sketchy links when our fleeting curiosity gets the better of us. You can add a layer of security against potentially malicious URLs by using the Cloudmersive Virus Scan API’s /virus/scan/website iteration, which will scan a URL for various types of malicious content, including viruses & phishing attempts among others. You can easily take advantage of this API with ready-to-run code snippets available in the Cloudmersive API console. Below, we’ll walk through connecting for Python.

Let’s kick things by running the below command to install the Python SDK:

pip install cloudmersive-virus-api-client

After that, copy in the API callback function below. If you don’t currently have a Cloudmersive API key, quickly make a free account on the Cloudmersive website to receive one (this will enable 800 free API calls per month), then copy your key into the second snippet below where indicated. After that, you’re ready to scan.

from __future__ import print_function
import time
import cloudmersive_virus_api_client
from cloudmersive_virus_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_virus_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_virus_api_client.ScanApi(cloudmersive_virus_api_client.ApiClient(configuration))
input = cloudmersive_virus_api_client.WebsiteScanRequest() # WebsiteScanRequest |
try:
# Scan a website for malicious content and threats
api_response = api_instance.scan_website(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling ScanApi->scan_website: %s\n" % e)

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.