2018-03-13 17:30:22 -04:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using System;
|
2018-03-09 03:01:12 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-04-08 14:48:40 -04:00
|
|
|
|
namespace IW4MAdmin.Application.Misc
|
2018-03-09 03:01:12 -05:00
|
|
|
|
{
|
|
|
|
|
public class VPNCheck
|
|
|
|
|
{
|
2018-03-14 01:36:25 -04:00
|
|
|
|
public static async Task<bool> UsingVPN(string ip, string apiKey)
|
2018-03-09 03:01:12 -05:00
|
|
|
|
{
|
2018-03-13 17:30:22 -04:00
|
|
|
|
#if DEBUG
|
2018-03-18 22:25:11 -04:00
|
|
|
|
return await Task.FromResult(false);
|
|
|
|
|
|
|
|
|
|
#else
|
2018-03-09 03:01:12 -05:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var RequestClient = new System.Net.Http.HttpClient())
|
|
|
|
|
{
|
2018-03-14 01:36:25 -04:00
|
|
|
|
RequestClient.DefaultRequestHeaders.Add("X-Key", apiKey);
|
2018-03-13 17:30:22 -04:00
|
|
|
|
string response = await RequestClient.GetStringAsync($"http://v2.api.iphub.info/ip/{ip}");
|
|
|
|
|
var responseJson = JsonConvert.DeserializeObject<JObject>(response);
|
|
|
|
|
int blockType = Convert.ToInt32(responseJson["block"]);
|
|
|
|
|
return blockType == 1;
|
2018-03-09 03:01:12 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-03-18 22:25:11 -04:00
|
|
|
|
#endif
|
2018-03-09 03:01:12 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|