IW4M-Admin/Application/Misc/VPNCheck.cs

43 lines
1.2 KiB
C#
Raw Normal View History

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;
namespace Application.Misc
2018-03-09 03:01:12 -05:00
{
public class VPNCheck
{
public static async Task<bool> UsingVPN(string ip, string apiKey)
2018-03-09 03:01:12 -05:00
{
#if DEBUG
return await Task.FromResult(false);
#else
2018-03-09 03:01:12 -05:00
try
{
using (var RequestClient = new System.Net.Http.HttpClient())
{
RequestClient.DefaultRequestHeaders.Add("X-Key", apiKey);
string response = await RequestClient.GetStringAsync($"http://v2.api.iphub.info/ip/{ip}");
var responseJson = JsonConvert.DeserializeObject<JObject>(response);
int blockType = Convert.ToInt32(responseJson["block"]);
/*if (responseJson.ContainsKey("isp"))
{
if (responseJson["isp"].ToString() == "TSF-IP-CORE")
return true;
}*/
return blockType == 1;
2018-03-09 03:01:12 -05:00
}
}
catch (Exception)
{
return false;
}
#endif
2018-03-09 03:01:12 -05:00
}
}
}