mirror of https://github.com/quasar/Quasar.git
Reverted GeoIP as it's online again
This commit is contained in:
parent
584ea70797
commit
cebc1d279f
|
@ -1,10 +1,10 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.RegularExpressions;
|
using System.Xml;
|
||||||
|
|
||||||
namespace xClient.Core
|
namespace xClient.Core
|
||||||
{
|
{
|
||||||
public class GeoIP
|
class GeoIP
|
||||||
{
|
{
|
||||||
public string WANIP { get; private set; }
|
public string WANIP { get; private set; }
|
||||||
public string Country { get; private set; }
|
public string Country { get; private set; }
|
||||||
|
@ -12,29 +12,11 @@ namespace xClient.Core
|
||||||
public string Region { get; private set; }
|
public string Region { get; private set; }
|
||||||
public string City { get; private set; }
|
public string City { get; private set; }
|
||||||
|
|
||||||
private string GetWANIP()
|
|
||||||
{
|
|
||||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://checkip.dyndns.org");
|
|
||||||
request.Proxy = null;
|
|
||||||
request.Timeout = 5000;
|
|
||||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
||||||
Stream dataStream = response.GetResponseStream();
|
|
||||||
StreamReader reader = new StreamReader(dataStream);
|
|
||||||
string responseString = reader.ReadToEnd();
|
|
||||||
reader.Close();
|
|
||||||
dataStream.Close();
|
|
||||||
response.Close();
|
|
||||||
|
|
||||||
responseString = (new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")).Match(responseString).Value;
|
|
||||||
return responseString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GeoIP()
|
public GeoIP()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WANIP = GetWANIP();
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://freegeoip.net/xml/");
|
||||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("http://api.hackertarget.com/geoip/?q={0}", WANIP));
|
|
||||||
request.Proxy = null;
|
request.Proxy = null;
|
||||||
request.Timeout = 5000;
|
request.Timeout = 5000;
|
||||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||||
|
@ -45,24 +27,14 @@ namespace xClient.Core
|
||||||
dataStream.Close();
|
dataStream.Close();
|
||||||
response.Close();
|
response.Close();
|
||||||
|
|
||||||
string[] resp = responseString.Split('\n');
|
XmlDocument doc = new XmlDocument();
|
||||||
|
doc.LoadXml(responseString);
|
||||||
|
|
||||||
foreach (string line in resp)
|
WANIP = doc.SelectSingleNode("Response//IP").InnerXml;
|
||||||
{
|
Country = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//CountryName").InnerXml)) ? doc.SelectSingleNode("Response//CountryName").InnerXml : "Unknown";
|
||||||
if (line.StartsWith("Country: "))
|
CountryCode = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//CountryCode").InnerXml)) ? doc.SelectSingleNode("Response//CountryCode").InnerXml : "-";
|
||||||
{
|
Region = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//RegionName").InnerXml)) ? doc.SelectSingleNode("Response//RegionName").InnerXml : "Unknown";
|
||||||
Country = line.Replace("Country: ", string.Empty);
|
City = (!string.IsNullOrEmpty(doc.SelectSingleNode("Response//City").InnerXml)) ? doc.SelectSingleNode("Response//City").InnerXml : "Unknown";
|
||||||
CountryCode = Country;
|
|
||||||
}
|
|
||||||
else if (line.StartsWith("State: "))
|
|
||||||
{
|
|
||||||
Region = line.Replace("State: ", string.Empty);
|
|
||||||
}
|
|
||||||
else if (line.StartsWith("City: "))
|
|
||||||
{
|
|
||||||
City = line.Replace("City: ", string.Empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -74,4 +46,4 @@ namespace xClient.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue