How to Scan a Website URL for Threats in C# .NET Core

Cloudmersive
2 min readMay 30, 2024

--

Clicking on malicious website URLs can lead to virus downloads, phishing scams, and other problematic outcomes.

Thankfully, we can look under the hood of any website URL using a few lines of code.

We can use the ready-to-run C# .NET Core code examples below to call a free API that scans website URLs for a few different types of malicious content — including viruses and known phishing domains.

We can authorize our API calls with a free Cloudmersive API key, and we’ll be able to check up to 800 URLs per month with zero commitments (our API call total will reset the following month).

To structure our API call, we can start by installing the client SDK via NuGet. Let’s run the following command in our Package Manager console:

Install-Package Cloudmersive.APIClient.NETCore.VirusScan -Version 2.0.4

Next, we can add our namespace imports and call our threat scanning function. We can replace the “YOUR_API_KEY” placeholder text with our API key string:

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NETCore.VirusScan.Api;
using Cloudmersive.APIClient.NETCore.VirusScan.Client;
using Cloudmersive.APIClient.NETCore.VirusScan.Model;

namespace Example
{
public class ScanWebsiteExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");

var apiInstance = new ScanApi();
var input = new WebsiteScanRequest(); // WebsiteScanRequest |

try
{
// Scan a website for malicious content and threats
WebsiteScanResult result = apiInstance.ScanWebsite(input);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ScanApi.ScanWebsite: " + e.Message );
}
}
}
}

Below, we can take a look at an example JSON response model. The “WebsiteThreatType” value will identify which type of threat was detected in a “CleanResult”: false scenario, and if a virus was identified, we’ll get information about it in the “FoundViruses” value.

{
"CleanResult": true,
"WebsiteThreatType": "None",
"FoundViruses": [
{
"FileName": "string",
"VirusName": "string"
}
],
"WebsiteHttpResponseCode": 0
}

That’s all the code we’ll need — now we can quickly and easily scan website URLs for potential threats in our .NET Core application.

--

--

Cloudmersive

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