public void DiscoverIp(ConnectionInfo connection) { IpAddress ip = connection.IpsEntry.FirstPreferIPv4; if (ip != null) { Json jDoc = DiscoverIpData(ip.Address, ""); if (jDoc != null) { // Node parsing if (jDoc.HasKey("country_code")) { string countryCode = Conversions.ToString(jDoc["country_code"].Value).Trim().ToLowerInvariant(); if (CountriesManager.IsCountryCode(countryCode)) { if (connection.CountryCode != countryCode) { connection.CountryCode = countryCode; Engine.Instance.MarkServersListUpdated(); Engine.Instance.MarkAreasListUpdated(); } } } if (jDoc.HasKey("city_name")) { string cityName = Conversions.ToString(jDoc["city_name"].Value).Trim(); if (cityName == "N/A") { cityName = ""; } if (cityName != "") { connection.Location = cityName; Engine.Instance.MarkServersListUpdated(); } } if ((jDoc.HasKey("latitude")) && (jDoc.HasKey("longitude"))) { double latitude = Conversions.ToDouble(jDoc["latitude"].Value); double longitude = Conversions.ToDouble(jDoc["longitude"].Value); connection.Latitude = latitude; connection.Longitude = longitude; Engine.Instance.MarkServersListUpdated(); } } } connection.LastDiscover = UtilsCore.UnixTimeStamp(); connection.Provider.OnChangeConnection(connection); }
public void DiscoverIp(ConnectionInfo connection) { XmlDocument xmlDoc = DiscoverIpData(connection.IpsEntry.ToStringFirstIPv4(), ""); if (xmlDoc != null) { // Node parsing string countryCode = Utils.XmlGetBody(xmlDoc.DocumentElement.SelectSingleNode(".//country_code") as XmlElement).ToLowerInvariant().Trim(); if (CountriesManager.IsCountryCode(countryCode)) { if (connection.CountryCode != countryCode) { connection.CountryCode = countryCode; Engine.Instance.MarkServersListUpdated(); Engine.Instance.MarkAreasListUpdated(); } } string cityName = Utils.XmlGetBody(xmlDoc.DocumentElement.SelectSingleNode(".//city_name") as XmlElement).Trim(); if (cityName == "N/A") { cityName = ""; } if (cityName != "") { connection.Location = cityName; Engine.Instance.MarkServersListUpdated(); } float latitude = Conversions.ToFloat(Utils.XmlGetBody(xmlDoc.DocumentElement.SelectSingleNode(".//latitude") as XmlElement).Trim()); float longitude = Conversions.ToFloat(Utils.XmlGetBody(xmlDoc.DocumentElement.SelectSingleNode(".//longitude") as XmlElement).Trim()); if ((latitude != 0) && (longitude != 0)) { connection.Latitude = latitude; connection.Longitude = longitude; Engine.Instance.MarkServersListUpdated(); } } connection.LastDiscover = Utils.UnixTimeStamp(); connection.Provider.OnChangeConnection(connection); }
public void DiscoverIp(ServerInfo server) { string[] methods = Engine.Instance.Storage.Get("discover.ip_webservice.list").Split(';'); bool onlyFirstResponse = Engine.Instance.Storage.GetBool("discover.ip_webservice.first"); foreach (string method in methods) { try { if ((method.StartsWith("http://")) || (method.StartsWith("https://"))) { // Fetch a webservice string url = method; url = url.Replace("{@ip}", server.IpEntry); XmlDocument xmlDoc = Engine.Instance.XmlFromUrl(url, null, "iptitle", false); // Clodo: Bypass proxy? if (xmlDoc.DocumentElement.HasChildNodes) { // Node renaming Utils.XmlRenameTagName(xmlDoc.DocumentElement, "CountryCode", "country_code"); // Node parsing //string countryCode = Utils.XmlGetBody(Utils.XmlGetFirstElementByTagName(xmlDoc.DocumentElement, "country_code")).ToLowerInvariant().Trim(); string countryCode = Utils.XmlGetBody(xmlDoc.DocumentElement.SelectSingleNode(".//country_code") as XmlElement).ToLowerInvariant().Trim(); if (CountriesManager.IsCountryCode(countryCode)) { if (server.CountryCode != countryCode) { server.CountryCode = countryCode; Engine.Instance.MarkServersListUpdated(); Engine.Instance.MarkAreasListUpdated(); } } string cityName = Utils.XmlGetBody(xmlDoc.DocumentElement.SelectSingleNode(".//city_name") as XmlElement).Trim(); if (cityName == "N/A") { cityName = ""; } if (cityName != "") { server.Location = cityName; } if (onlyFirstResponse) { break; } } else { Engine.Instance.Logs.Log(LogType.Fatal, "Unable to fetch " + url); } } } catch (Exception) { } } }