Skip to content

Commit

Permalink
Merge pull request #2 from top-gg/master
Browse files Browse the repository at this point in the history
feat: add risk as parameter
  • Loading branch information
hollow87 authored Dec 19, 2024
2 parents f52ff68 + c01cbaf commit 0a31f53
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 12 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish .NET Package

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x' # Change this to the .NET version you are using
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: Publish
run: dotnet pack --configuration Release --no-build --output ./artifacts
- name: Push to GitHub Packages
run: dotnet nuget push ./artifacts/*.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/top-gg/index.json --skip-duplicate

env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ProxyCheckUtil
{
public interface IProxyChceckCacheProvider
public interface IProxyCheckCacheProvider

Check warning on line 6 in ProxyCheck/IProxyCheckCacheProvider.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'IProxyCheckCacheProvider'
{
ProxyCheckResult.IpResult GetCacheRecord(IPAddress ip, ProxyCheckRequestOptions options);

Check warning on line 8 in ProxyCheck/IProxyCheckCacheProvider.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'IProxyCheckCacheProvider.GetCacheRecord(IPAddress, ProxyCheckRequestOptions)'

Expand Down
33 changes: 23 additions & 10 deletions ProxyCheck/ProxyCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ProxyCheck
/// </summary>
/// <param name="apiKey">API key to use</param>
/// <param name="cacheProvider">Cache provider to use</param>
public ProxyCheck(string apiKey = "", IProxyChceckCacheProvider cacheProvider = null)
public ProxyCheck(string apiKey = "", IProxyCheckCacheProvider cacheProvider = null)
{
if (apiKey == null)
apiKey = string.Empty;
Expand All @@ -56,17 +56,16 @@ public ProxyCheck(string apiKey = "", IProxyChceckCacheProvider cacheProvider =
CacheProvider = cacheProvider;
}

public ProxyCheck(IProxyChceckCacheProvider cacheProvider)
public ProxyCheck(IProxyCheckCacheProvider cacheProvider)

Check warning on line 59 in ProxyCheck/ProxyCheck.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ProxyCheck.ProxyCheck(IProxyCheckCacheProvider)'
{
CacheProvider = cacheProvider;
}

private const string PROXYCHECKURL = "proxycheck.io/v2";
private const string ProxyCheckUrl = "proxycheck.io/v2";

private ProxyCheckRequestOptions _options = new ProxyCheckRequestOptions();


public IProxyChceckCacheProvider CacheProvider { get; set; }

public IProxyCheckCacheProvider CacheProvider { get; set; }

Check warning on line 68 in ProxyCheck/ProxyCheck.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'ProxyCheck.CacheProvider'

/// <summary>
/// The API key to use with the query
Expand Down Expand Up @@ -158,7 +157,16 @@ public bool IncludeLastSeen
/// </summary>
public int DayLimit { get; set; } = 7;


/// <summary>
/// Determines whether you will receive a risk score with the result. If enabled, a risk score will be included
/// with your response.<br/>
/// (Default: <see cref="RiskLevel.Disabled"/>)
/// </summary>
public RiskLevel RiskLevel
{
get => _options.RiskLevel ?? RiskLevel.Disabled;
set => _options.RiskLevel = value;
}


/// <summary>
Expand Down Expand Up @@ -274,7 +282,7 @@ public async Task<ProxyCheckResult> QueryAsync(IPAddress[] ipAddresses, string t
}

var url = new StringBuilder()
.Append($"{(UseTLS ? "https://" : "http://")}{PROXYCHECKURL}/")
.Append($"{(UseTLS ? "https://" : "http://")}{ProxyCheckUrl}/")
.Append(!string.IsNullOrWhiteSpace(ApiKey) ? $"&key={ApiKey}" : "")
.Append($"&vpn={Convert.ToInt32(IncludeVPN)}")
.Append($"&asn={Convert.ToInt32(IncludeASN)}")
Expand All @@ -283,7 +291,8 @@ public async Task<ProxyCheckResult> QueryAsync(IPAddress[] ipAddresses, string t
.Append($"&inf={Convert.ToInt32(UseInference)}")
.Append($"&port={Convert.ToInt32(IncludePort)}")
.Append($"&seen={Convert.ToInt32(IncludeLastSeen)}")
.Append($"&days={Convert.ToInt32(DayLimit)}");
.Append($"&days={Convert.ToInt32(DayLimit)}")
.Append($"&risk={Convert.ToInt32(RiskLevel)}");

using (var client = new HttpClient())
{
Expand Down Expand Up @@ -412,7 +421,11 @@ private ProxyCheckResult ParseJson(string json)
string isProxy = (string) innerToken.Value;
ipResult.IsProxy = isProxy.Equals("yes", StringComparison.OrdinalIgnoreCase);
break;


case "risk":
ipResult.RiskScore = Convert.ToInt32((string)innerToken.Value);
break;

case "type":
ipResult.ProxyType = (string)innerToken.Value;
break;
Expand Down
10 changes: 10 additions & 0 deletions ProxyCheck/ProxyCheckRequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public class ProxyCheckRequestOptions
/// </summary>
public bool IncludeLastSeen { get; set; }

/// <summary>
/// Determines whether you will receive a risk score with the result. If enabled, a risk score will be included
/// with your response.<br/>
/// (Default: <see cref="RiskLevel.Disabled"/>)
/// </summary>
public RiskLevel? RiskLevel { get; set; }

public override bool Equals(object obj)
{
if (!(obj is ProxyCheckRequestOptions o))
Expand All @@ -61,6 +68,9 @@ public override bool Equals(object obj)
if (IncludePort != o.IncludePort)
return false;

if (RiskLevel != o.RiskLevel)
return false;

return IncludeLastSeen == o.IncludeLastSeen;
}
}
Expand Down
5 changes: 5 additions & 0 deletions ProxyCheck/ProxyCheckResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public class IpResult
/// </summary>
public int? Port { get; set; }

/// <summary>
/// Not null when risk is > 0, the risk score of the IP address
/// </summary>
public int? RiskScore { get; set; }

/// <summary>
/// The last time the proxy server was seen in human readable format.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions ProxyCheck/RiskLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ProxyCheckUtil
{
public enum RiskLevel
{
Disabled = 0,
Enable = 1,
EnableWithAttackData = 2
}
}
2 changes: 1 addition & 1 deletion ProxyCheck/SimpleInMemoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ProxyCheckUtil
{
public class SimpleInMemoryCache : IProxyChceckCacheProvider
public class SimpleInMemoryCache : IProxyCheckCacheProvider
{
private List<CacheItem> _cacheItems = new List<CacheItem>();
private TimeSpan _maxCacheAge = TimeSpan.FromHours(1);
Expand Down

0 comments on commit 0a31f53

Please sign in to comment.