Skip to content

Commit 06d4304

Browse files
committed
Version 1.3.5
- Added .NET 7 as a supported target framework - Improved the CSPROJ and README files - Other minor changes
1 parent e7a4e49 commit 06d4304

9 files changed

Lines changed: 106 additions & 88 deletions

File tree

Example/Example.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>
99
<ProjectReference Include="..\Urlscan\Urlscan.csproj" />
1010
</ItemGroup>
1111

12-
</Project>
12+
</Project>

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,31 @@
99
</div>
1010

1111
## Usage
12-
Available on NuGet as `Urlscan`, methods can be found under the classes `UrlscanClient` and `LiveClient`.<br>
13-
https://www.nuget.org/packages/Urlscan
12+
Provides an easy interface for interacting with the Urlscan API.
13+
14+
You can use this library to automate your Urlscan submissions, search for existing scans, track newly submitted scans and analyse network activity of malicious websites.
15+
16+
To get started, add the library into your solution with either the `NuGet Package Manager` or the `dotnet` CLI.
17+
```rust
18+
dotnet add package Urlscan
19+
```
20+
21+
For the primary classes to become available, import the used namespace.
22+
```csharp
23+
using Urlscan;
24+
```
25+
26+
Need more examples? Under the `Example` directory you can find a working demo project that implements this library.
1427

1528
### Obtaining API keys
1629
> API keys can be created in the user section `Settings & API`
1730
1831
> Secure identifier SID cookies can be obtained from your browser's cookie storage. Make sure to only copy the value, without the name!
1932
2033
## Features
21-
- Made with **.NET 6**
34+
- Built for **.NET 6** and **.NET 7**
2235
- Fully **async**
23-
- Extensive **documentation**
36+
- Extensive **XML documentation**
2437
- Coverage of the free API endpoints, including some user-only and beta routes
2538
- **No external dependencies** (uses integrated HTTP and JSON)
2639
- **Custom exceptions** (`UrlscanException`) for advanced catching
@@ -30,9 +43,6 @@ https://www.nuget.org/packages/Urlscan
3043
- Download screenshots and page DOMs
3144
- Empower your threat intelligence with live scans through `LiveClient`
3245

33-
## Example
34-
Under the `Example` directory you can find a working demo project that implements this library.
35-
3646
## Code Samples
3747

3848
### Initializing a new API client
@@ -116,13 +126,13 @@ await client.AddVerdict(new VerdictParameters()
116126
- Task\<Stream> **LiveshotStream**(string url, int width = 1280, int height = 1024)
117127
- Task\<string> **DownloadDOM**(Result result)
118128
- Task\<string> **DownloadDOM**(string uuid)
119-
- Task\<Submission> **Scan**( string url, string[] tags = null, string userAgent = null, string referer = null, bool overrideSafety = false, Visibility visibility = Visibility.Public, ScanCountry country = ScanCountry.Auto )
129+
- Task\<Submission> **Scan**(string url, string[] tags = null, string userAgent = null, string referer = null, bool overrideSafety = false, Visibility visibility = Visibility.Public, ScanCountry country = ScanCountry.Auto)
120130
- Task\<Submission> **Scan**(ScanParameters parameters)
121131
- Task\<User> **GetCurrentUser**()
122132

123133
## Available Events
124134
- EventHandler\<LiveScan> `UrlScanned`
125135

126-
## Official Links
127-
https://urlscan.io</br>
128-
https://twitter.com/urlscanio
136+
## References
137+
- https://urlscan.io
138+
- https://twitter.com/urlscanio

Urlscan/API.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Net;
34
using System.Net.Http;
45
using System.Net.Http.Headers;
@@ -52,7 +53,7 @@ public static async Task<HttpResponseMessage> Request
5253

5354
while (retries < MaxRetries)
5455
{
55-
HttpRequestMessage req = new(method, absoluteUrl ? url : $"api/v{UrlscanClient.Version}/{url}")
56+
HttpRequestMessage req = new(method, absoluteUrl ? url : $"api/v{Constants.Version}/{url}")
5657
{
5758
Content = content
5859
};
@@ -123,16 +124,19 @@ public static async Task<HttpResponseMessage> Request
123124

124125
public static async Task<T> Deseralize<T>(this HttpResponseMessage res, JsonSerializerOptions options = null)
125126
{
126-
string json = await res.Content.ReadAsStringAsync();
127-
if (string.IsNullOrEmpty(json)) throw new UrlscanException("Response content is empty, can't parse as JSON.");
127+
Stream stream = await res.Content.ReadAsStreamAsync();
128+
if (stream.Length == 0) throw new UrlscanException("Response content is empty, can't parse as JSON.");
128129

129130
try
130131
{
131-
return JsonSerializer.Deserialize<T>(json, options ?? Constants.JsonOptions);
132+
return await JsonSerializer.DeserializeAsync<T>(stream, options ?? Constants.JsonOptions);
132133
}
133134
catch (Exception ex)
134135
{
135-
throw new($"Exception while parsing JSON: {ex.GetType().Name} => {ex.Message}\nJSON preview: {json[..Math.Min(json.Length, PreviewMaxLength)]}");
136+
using StreamReader sr = new(stream);
137+
string text = await sr.ReadToEndAsync();
138+
139+
throw new($"Exception while parsing JSON: {ex.GetType().Name} => {ex.Message}\nPreview: {text[..Math.Min(text.Length, PreviewMaxLength)]}");
136140
}
137141
}
138142
}

Urlscan/Constants.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
using System.Text.Json;
1+
using System;
2+
using System.Text.Json;
23
using System.Text.Json.Serialization;
34

45
namespace Urlscan
56
{
67
internal class Constants
78
{
9+
/// <summary>
10+
/// The API version to use when communicating.
11+
/// </summary>
12+
public const int Version = 1;
13+
14+
public static readonly Version HttpVersion = new(2, 0);
15+
public static readonly TimeSpan Timeout = TimeSpan.FromSeconds(30);
16+
17+
public const string UserAgent = "Urlscan C# Client - actually-akac/Urlscan";
818
public const string JsonContentType = "application/json";
9-
public static readonly string HtmlContentType = "text/html";
19+
public const string HtmlContentType = "text/html";
1020
public const int ErrorStatusCode = 500;
21+
1122
public const string SuccessSubmissionMessage = "Submission successful";
1223

1324
public static readonly JsonSerializerOptions JsonOptions = new()

Urlscan/Extensions.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ namespace Urlscan
66
internal static class Extensions
77
{
88
public static DateTime ToDate(this long value)
9-
{
10-
return DateTime.UnixEpoch.AddSeconds(value);
11-
}
9+
=> DateTime.UnixEpoch.AddSeconds(value);
1210

1311
public static long ToUnixSeconds(this DateTime value)
14-
{
15-
return (long)(value - DateTime.UnixEpoch).TotalSeconds;
16-
}
12+
=> (long)(value - DateTime.UnixEpoch).TotalSeconds;
1713

1814
public static string ToKebabCase(this string str) =>
1915
string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "-" + x.ToString() : x.ToString())).ToLower();

Urlscan/Live.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ namespace Urlscan
1515
/// </summary>
1616
public class LiveClient
1717
{
18-
private readonly HttpClientHandler HttpHandler = new()
18+
private static readonly HttpClientHandler HttpHandler = new()
1919
{
2020
AutomaticDecompression = DecompressionMethods.All
2121
};
2222

23-
private readonly HttpClient Client;
23+
private readonly HttpClient Client = new(HttpHandler)
24+
{
25+
BaseAddress = UrlscanClient.BaseUri,
26+
Timeout = Constants.Timeout,
27+
DefaultRequestVersion = Constants.HttpVersion
28+
};
2429

2530
private EventHandler<LiveScan> Handler;
2631
public event EventHandler<LiveScan> UrlScanned
@@ -51,15 +56,9 @@ public LiveClient(int interval = 30000, int size = 100)
5156
if (size <= 0) throw new ArgumentOutOfRangeException(nameof(size), "Poll size has to be at least 1.");
5257

5358
Interval = interval;
54-
Size = size;
5559

60+
Size = size;
5661
Seen = new(Size);
57-
Client = new(HttpHandler)
58-
{
59-
BaseAddress = UrlscanClient.BaseUri,
60-
Timeout = UrlscanClient.Timeout,
61-
DefaultRequestVersion = UrlscanClient.HttpVersion
62-
};
6362

6463
Client.DefaultRequestHeaders.AcceptEncoding.ParseAdd("gzip, deflate, br");
6564
Client.DefaultRequestHeaders.UserAgent.ParseAdd("Urlscan C# Live Client - actually-akac/Urlscan");

Urlscan/README_NuGet.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@
55
🔎 An async and lightweight C# library for interacting with the Urlscan API.
66

77
## Usage
8-
Available on NuGet as `Urlscan`, methods can be found under the classes `UrlscanClient` and `LiveClient`.
8+
Provides an easy interface for interacting with the Urlscan API.
99

10-
https://www.nuget.org/packages/Urlscan
10+
You can use this library to automate your Urlscan submissions, search for existing scans, track newly submitted scans and analyse network activity of malicious websites.
11+
12+
To get started, add the library into your solution with either the `NuGet Package Manager` or the `dotnet` CLI.
13+
```rust
14+
dotnet add package Urlscan
15+
```
16+
17+
For the primary classes to become available, import the used namespace.
18+
```csharp
19+
using Urlscan;
20+
```
21+
22+
Need more examples? Under the `Example` directory you can find a working demo project that implements this library.
1123

1224
### Obtaining API keys
1325
> API keys can be created in the user section `Settings & API`
1426
1527
> Secure identifier SID cookies can be obtained from your browser's cookie storage. Make sure to only copy the value, without the name!
1628
1729
## Features
18-
- Made with **.NET 6**
30+
- Built for **.NET 6** and **.NET 7**
1931
- Fully **async**
20-
- Extensive **documentation**
32+
- Extensive **XML documentation**
2133
- Coverage of the free API endpoints, including some user-only and beta routes
2234
- **No external dependencies** (uses integrated HTTP and JSON)
2335
- **Custom exceptions** (`UrlscanException`) for advanced catching
@@ -27,9 +39,6 @@ https://www.nuget.org/packages/Urlscan
2739
- Download screenshots and page DOMs
2840
- Empower your threat intelligence with live scans through `LiveClient`
2941

30-
## Example
31-
Under the `Example` directory you can find a working demo project that implements this library.
32-
3342
## Code Samples
3443

3544
### Initializing a new API client
@@ -113,14 +122,13 @@ await client.AddVerdict(new VerdictParameters()
113122
- Task\<Stream> **LiveshotStream**(string url, int width = 1280, int height = 1024)
114123
- Task\<string> **DownloadDOM**(Result result)
115124
- Task\<string> **DownloadDOM**(string uuid)
116-
- Task\<Submission> **Scan**( string url, string[] tags = null, string userAgent = null, string referer = null, bool overrideSafety = false, Visibility visibility = Visibility.Public, ScanCountry country = ScanCountry.Auto )
125+
- Task\<Submission> **Scan**(string url, string[] tags = null, string userAgent = null, string referer = null, bool overrideSafety = false, Visibility visibility = Visibility.Public, ScanCountry country = ScanCountry.Auto)
117126
- Task\<Submission> **Scan**(ScanParameters parameters)
118127
- Task\<User> **GetCurrentUser**()
119128

120129
## Available Events
121130
- EventHandler\<LiveScan> `UrlScanned`
122131

123-
## Official Links
124-
https://urlscan.io
125-
126-
https://twitter.com/urlscanio
132+
## References
133+
- https://urlscan.io
134+
- https://twitter.com/urlscanio

Urlscan/Urlscan.cs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,26 @@ namespace Urlscan
1515
/// </summary>
1616
public class UrlscanClient
1717
{
18-
/// <summary>
19-
/// The API version to use when communicating.
20-
/// </summary>
21-
public const int Version = 1;
22-
23-
/// <summary>
24-
/// The base URL to use when communicating.
25-
/// </summary>
26-
public const string BaseUrl = "https://urlscan.io/";
27-
2818
/// <summary>
2919
/// The base URI to use when communicating.
3020
/// </summary>
31-
public static readonly Uri BaseUri = new(BaseUrl);
32-
33-
/// <summary>
34-
/// The HTTP request version to use when communicating.
35-
/// </summary>s
36-
public static readonly Version HttpVersion = new(2, 0);
37-
38-
/// <summary>
39-
/// The maximum duration to wait for a response from the server.
40-
/// </summary>
41-
public static readonly TimeSpan Timeout = TimeSpan.FromSeconds(30);
42-
21+
public static readonly Uri BaseUri = new("https://urlscan.io/");
4322
/// <summary>
4423
/// How many times result polling should be retried.
4524
/// </summary>
4625
private const int MaxPollingRetries = 20;
4726

48-
private readonly HttpClientHandler HttpHandler = new()
27+
private static readonly HttpClientHandler HttpHandler = new()
4928
{
5029
AutomaticDecompression = DecompressionMethods.All
5130
};
5231

53-
private readonly HttpClient Client;
32+
private readonly HttpClient Client = new(HttpHandler)
33+
{
34+
BaseAddress = BaseUri,
35+
DefaultRequestVersion = Constants.HttpVersion,
36+
Timeout = Constants.Timeout,
37+
};
5438

5539
private readonly string Key;
5640
private readonly string Sid;
@@ -71,15 +55,8 @@ public UrlscanClient(string key, string sid = null)
7155
Sid = sid;
7256
UsesAccountSID = sid is not null;
7357

74-
Client = new(HttpHandler)
75-
{
76-
BaseAddress = BaseUri,
77-
DefaultRequestVersion = HttpVersion,
78-
Timeout = Timeout
79-
};
80-
8158
Client.DefaultRequestHeaders.AcceptEncoding.ParseAdd("gzip, deflate, br");
82-
Client.DefaultRequestHeaders.UserAgent.ParseAdd("Urlscan C# Client - actually-akac/Urlscan");
59+
Client.DefaultRequestHeaders.UserAgent.ParseAdd(Constants.UserAgent);
8360
Client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
8461
Client.DefaultRequestHeaders.Add("API-Key", Key);
8562
}

Urlscan/Urlscan.csproj

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<!--Basic Information-->
5+
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
56
<PackageId>Urlscan</PackageId>
67
<Product>Urlscan</Product>
7-
<Version>1.3.4</Version>
8-
<AssemblyVersion>1.3.4</AssemblyVersion>
9-
<FileVersion>1.3.4</FileVersion>
108
<Authors>akac</Authors>
119
<Company>akac</Company>
1210
<Description>An async and lightweight C# library for interacting with the Urlscan API.</Description>
1311
<PackageTags>urlscan; url-scan; url; scan; ioc; ip; domain; screenshot; phishing; malware; link; suspicious; check</PackageTags>
12+
<PackageIcon>icon.png</PackageIcon>
13+
<PackageReadmeFile>README_NuGet.md</PackageReadmeFile>
14+
15+
<!--Version-->
16+
<Version>1.3.5</Version>
17+
<AssemblyVersion>1.3.5</AssemblyVersion>
18+
<FileVersion>1.3.5</FileVersion>
19+
20+
<!--Github-->
1421
<PackageProjectUrl>https://github.com/actually-akac/Urlscan</PackageProjectUrl>
1522
<RepositoryUrl>https://github.com/actually-akac/Urlscan</RepositoryUrl>
1623
<RepositoryType>git</RepositoryType>
24+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
25+
26+
<!--Compiler Options-->
27+
<IncludeSymbols>true</IncludeSymbols>
28+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
29+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
30+
31+
<!--Miscellaneous-->
1732
<PackageLicenseExpression>MIT</PackageLicenseExpression>
18-
<PackageIcon>icon.png</PackageIcon>
33+
<RequireLicenseAcceptance>false</RequireLicenseAcceptance>
1934
<NeutralLanguage>en</NeutralLanguage>
20-
<PackageReadmeFile>README_NuGet.md</PackageReadmeFile>
21-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2235
</PropertyGroup>
2336

2437
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -30,11 +43,11 @@
3043
</PropertyGroup>
3144

3245
<ItemGroup>
33-
<None Update="icon.png">
46+
<None Include="icon.png">
3447
<Pack>True</Pack>
3548
<PackagePath>\</PackagePath>
3649
</None>
37-
<None Update="README_NuGet.md">
50+
<None Include="README_NuGet.md">
3851
<Pack>True</Pack>
3952
<PackagePath>\</PackagePath>
4053
</None>

0 commit comments

Comments
 (0)