private Task <IpData?> LoadMaxmind(IPAddress ip) { IpData?data = null; try { var city = _maxMind.City(ip); var asn = _maxMind.Asn(ip); if (city != null || asn != null) { data = new IpData { Asn = asn?.AutonomousSystemNumber, AsnName = asn?.AutonomousSystemOrganization, City = city?.City?.Name, Country = city?.Country?.Name, CountryIso = city?.Country?.IsoCode, }; } } catch (Exception ex) { _logger.LogError(ex, $"Could not load MaxMind data for {ip}: {ex.Message}"); } return(Task.FromResult(data)); }
private void LoadConfigIpCallback(string sIp, byte[] sConfig) { CheckState((string)ApplicationConst.dictStaticText["24"]); IpData.LoadIp(sIp); ConfigData.ParseConfig(sConfig); LoadConfigIpEndFunc(); }
public void ShouldReturnIpInfomationWhenIpIsValid() { // Arrange IpData data = new IpData { city = "Landon", country = "UK", countryCode = "UK", lon = "21.21", lat = "78.28", query = "123.32.32.21", region = "North-West", status = "success", timezone = "Western", zip = "12345" }; var ipMapper = new IPMapper(); // Act var response = ipMapper.Map(data); // Assert response.ShouldNotBeNull(); response.City.ShouldBe(data.city); }
public string GetCity() { string ipAddress = "155.120.20.3"; string pathToResourceModified = pathToResource.Replace("{ip}", ipAddress); string requestUri = string.Format("{0}://{1}/{2}", protocol, hostName, pathToResourceModified); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri); request.Method = HttpMethod; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string content = string.Empty; using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); content = reader.ReadToEnd(); } IpData data = JsonConvert.DeserializeObject <IpData>(content); //Console.WriteLine(string.Format("{0} is in {1} city of {2}, timezone {3}", ipAddress, data.City, data.Country, data.TimeZone)); return(data.City); // Console.ReadLine(); }
void Test() { HttpClient client = new HttpClient(); IpData ip = new IpData() { ip = "59.66.134.35" }; string url = "https://www.qqzeng.com/ip/"; HttpResponseMessage response = client.GetAsync(url).Result; HttpResponseHeaders heads = response.Headers; Dictionary <string, string> cookie = new Dictionary <string, string>(); List <string> cs = new List <string>(); foreach (var item in heads) { client.DefaultRequestHeaders.Add(item.Key, item.Value); string value = string.Join("", item.Value); cs.Add(item.Key + ":" + value); cookie.Add(item.Key, value); } string cookies = string.Join("\r\n", cs); string json = ip.ConvertJson(); HttpContent con = new StringContent(json, System.Text.Encoding.UTF8); // SetClientHeader(client,cookies); url = "https://www.qqzeng.com/ip/getIpInfo.php"; string text = client.PostAsync(url, con).Result.Content.ReadAsStringAsync().Result; QQZengResponse qqz = text.ConvertObject <QQZengResponse>(); }
public LocaleLookupBase(int?pId, IpData pData, string pIpAddress, Reference pLocale, int?pLocaleId) : this(DocConvert.ToInt(pId)) { Data = pData; IpAddress = pIpAddress; Locale = pLocale; LocaleId = pLocaleId; }
public void Deconstruct(out IpData pData, out string pIpAddress, out Reference pLocale, out int?pLocaleId) { pData = Data; pIpAddress = IpAddress; pLocale = Locale; pLocaleId = LocaleId; }
public void SetServerInfo() { List <string[]> list = IpData.GetServerList(); SetLastServer(IpData.GetCurServerData()); SetServerList(list); }
public static void SaveIps(IpData data) { var jsons = JsonConvert.SerializeObject(data); var axc = File.CreateText(Constants.CachePath + "/ips.json"); axc.Write(jsons); axc.Close(); }
public WeeklyDisplayData(WeatherAPI wAPI, IpData locationInfo) { // Iterira kroz data niz daily dela JSON response-a i // prikuplja informacije za <displayDayCount> dan(a). foreach (DailyWeatherData iter in wAPI.daily.data) { string dayLabel = GenerateDayLabel(iter.time); displayDays.Add(new DayData(dayLabel, iter.icon, "Max: " + Math.Round(iter.temperatureMax, 0) + "°C \nMin: " + Math.Round(iter.temperatureMin, 0) + "°C", "" + (iter.precipProbability * 100) + "%")); } }
private void SetLastServer(string[] firstServer) { string[] lastinfo = IpData.GetLastServerData(); if (null == lastinfo || lastinfo.Length <= 0) { lastinfo = firstServer; } m_lastLoginItem.SetInfo(-1, lastinfo[0], lastinfo[3]); }
private void OnClickServer() { if (_index < 0) { return; } IpData.SetCurServerData(_index); LoginPanel.GetInst().SetCurServer(); ServerListPanel.GetInst().ClosePanel(); }
public HourlyDisplayData(WeatherAPI wAPI, IpData locationInfo) { // Iterira kroz data niz hourly dela JSON response-a i // prikuplja informacije za <displayHourCount> sat(a). foreach (CurrentWeatherData iter in wAPI.hourly.data) { string hourLabel = GenerateHourLabel(iter.time); displayHours.Add(new HourData(hourLabel, iter.icon, Math.Round(iter.temperature, 0) + "°C", "" + (iter.precipProbability * 100) + " %")); } }
public ForecastController() { // Dohvatanje forecastApp instance. forecastAppInstance = ForecastApp.GetInstance(); // Weather info. weatherAPI = forecastAppInstance.WeatherDataFromJSON(); // City info. locationInfo = forecastAppInstance.IpAPIData; }
public async Task <IpData> GetGeoDetails(string ipAddress, string Url) { IpData geo = null; using (var client = new HttpClient()) { var result = await client.GetAsync(Url + ipAddress); var response = JObject.Parse(await result.Content.ReadAsStringAsync()); geo = JsonConvert.DeserializeObject <IpData>(response.ToString()); }; return(geo); }
public static IpData GetIps() { IpData data = new IpData(null, null); try { data = JsonConvert.DeserializeObject <IpData>(File.ReadAllText(Constants.CachePath + "/ips.json")); } catch (Exception) { File.Delete(Constants.CachePath + "/ips.json"); data = new IpData("", new Dictionary <string, string>()); } return(data); }
public TokenData Get(IpData data) { // Pass your credentials to the service string consumerKey = _settings.TwitterConsumerKey; string consumerSecret = _settings.TwitterConsumerSecret; // Try to validate token var service = new TwitterService(consumerKey, consumerSecret); service.AuthenticateWith(data.Token, data.TokenSecret); TwitterUser user = service.GetUserProfile(new GetUserProfileOptions()); if (user != null) { return(new TokenData { IdentityProvider = ProviderType.Twitter, Name = user.Name, UserIdentifier = string.Format(TwitterAccountPage, user.Id), Token = data.Token, TokenSecret = data.TokenSecret }); } // Check response status code switch (service.Response.StatusCode) { case HttpStatusCode.Unauthorized: case HttpStatusCode.BadRequest: throw new BadRequestException(); case (HttpStatusCode)429: throw new TooManyRequestsException(); } // Twitter internal errors if ((int)service.Response.StatusCode >= 500) { throw new BadGatewayException(service.Response.Response); } string message = string.Format("Unable to receive twitter profile. Status code {0}: {1}", service.Response.StatusCode, service.Response.InnerException); throw new InternalServerErrorException(message); }
public void OnConfigLoadEnd() { SetCurServer(); #if PLATFORM_IOS_SDK || PLATFORM_ANDROID_SDK wxNode.SetActive(true); hideNode.SetActive(false); #else wxNode.SetActive(false); hideNode.SetActive(true); #endif checkInfoLabel.text = string.Format(ConfigData.GetValue("InitValues_Common", "CHECK_INFO", "Value"), ApplicationConst.BundleVersion); if (IpData.GetServerCount() == 1) { curServerBtn.gameObject.SetActive(false); } }
public TokenData Get(IpData data) { // Try to validate token var service = new VkClient(); service.AuthenticateWith(data.Token); dynamic result; try { result = service.Get("users.get", new { fields = "screen_name" }); } catch (Exception e) { throw new BadGatewayException(e); } if (result.error != null) { dynamic message = result.error.error_msg ?? string.Empty; throw new BadRequestException(message.ToString()); } try { dynamic user = result.response[0]; return(new TokenData { IdentityProvider = ProviderType.Vk, Name = string.Format("{0} {1}", user.first_name, user.last_name), UserIdentifier = user.uid.ToString(), Token = data.Token, TokenSecret = data.TokenSecret }); } catch (Exception e) { string message = string.Format("Unable to receive VK profile: {0}", e); throw new InternalServerErrorException(message); } }
public TokenData Get(IpData data) { JObject claims = JObject.Parse(data.Token); var provider = (string)claims[CommonClaims.AcsIdentityProvider]; var identifier = (string)claims[CommonClaims.NameIdentifier]; var name = (string)claims[CommonClaims.Name]; var email = (string)claims[CommonClaims.Email]; return(new TokenData { Email = email, Name = name, IdentityProvider = IdentityTypeParser.ParseProviderType(provider), UserIdentifier = identifier, Token = GetToken(claims), TokenSecret = GetTokenSecret(claims) }); }
public GeoIpInfo Map(IpData data) { GeoIpInfo geoData = new GeoIpInfo(); if (data.status == "success") { geoData.Ip = data.query; geoData.Latitude = data.lat; geoData.Longititude = data.lon; geoData.Region = data.region; geoData.RegionName = data.regionName; geoData.TimeZone = data.timezone; geoData.Postal = data.zip; geoData.Country = data.country; geoData.CountryCode = data.countryCode; geoData.City = data.city; ; } return(geoData); }
public static string GetCityFromIp(string ip) { string pathToResourceModified = ResourcePath.Replace("{ip}", ip); string requestUri = $@"{Protocol}://{HostName}/{pathToResourceModified}"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri); request.Method = HttpMethod; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string content = string.Empty; using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); content = reader.ReadToEnd(); } IpData data = JsonConvert.DeserializeObject <IpData>(content); return(data.City); }
public string GetCityByIP() { string pathToResourceModified = pathToResource.Replace("{ip}", this.IP); string requestUri = string.Format("{0}://{1}/{2}", protocol, hostName, pathToResourceModified); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri); request.Method = HttpMethod; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string content = string.Empty; using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); content = reader.ReadToEnd(); } IpData data = JsonConvert.DeserializeObject <IpData>(content); return(data.City); }
public TokenData Get(IpData data) { // Try to validate token _service.AuthenticateWith(data.Token); dynamic user; try { user = _service.Get("users.getCurrentUser"); } catch (Exception e) { throw new BadGatewayException(e); } if (user.error_msg != null) { throw new BadRequestException(user.error_msg.ToString()); } try { return(new TokenData { IdentityProvider = ProviderType.Odnoklassniki, Name = user.name.ToString(), UserIdentifier = user.uid.ToString(), Token = data.Token, TokenSecret = data.TokenSecret }); } catch (Exception e) { string message = string.Format("Unable to receive Odnoklassniki profile: {0}", e); throw new InternalServerErrorException(message); } }
public TokenData Get(IpData data) { var client = new FacebookClient(data.Token); var result = new TokenData(); dynamic userData; try { userData = client.Get("me"); } catch (FacebookOAuthException e) { throw new BadRequestException(e); } catch (WebExceptionWrapper e) { throw new BadGatewayException(e); } result.IdentityProvider = ProviderType.Facebook; result.Name = userData.name; result.UserIdentifier = userData.id; result.Token = data.Token; result.TokenSecret = data.TokenSecret; // If email was not requested try { result.Email = userData.email; } catch { result.Email = null; } return(result); }
public static string GetCountry() { var ipAddress = Resource1.IP; string pathToResourceModified = pathToResource.Replace("{ip}", ipAddress); string requestUri = string.Format($"{protocol}://{hostName}/{pathToResourceModified}"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri); request.Method = HttpMethod; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string content = string.Empty; using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); content = reader.ReadToEnd(); } IpData data = JsonConvert.DeserializeObject <IpData>(content); return(data.City); }
public TokenData Get(IpData data) { // Validate security token var validator = new SimpleWebTokenValidator { SharedKeyBase64 = "ZY+lm6+MQeWVSeMdV+apXAaaIGNTZT7ztfBskldOMn0=" }; Dictionary <string, string> claims; try { claims = validator.ValidateToken(data.Token).Claims; } catch (HttpException e) { throw new BadRequestException(e); } catch (InvalidSecurityTokenException e) { throw new BadRequestException(e); } // Get values string identityProvider = claims.Single(p => p.Key == CommonClaims.AcsIdentityProvider).Value; return(new TokenData { UserIdentifier = claims.Single(p => p.Key == CommonClaims.NameIdentifier).Value, Name = claims.SingleOrDefault(p => p.Key == CommonClaims.Name).Value, Email = claims.SingleOrDefault(p => p.Key == CommonClaims.Email).Value, IdentityProvider = IdentityTypeParser.ParseProviderType(identityProvider), Token = GetToken(claims), TokenSecret = GetTokenSecret(claims) }); }
public void SaveAccount() { PlayerPrefs.SetString("LoginAccount", accountInput.text); PlayerPrefs.SetString("LoginPassword", passwordInput.text); IpData.WriteLastServerIndex(); }
public LocaleLookup(int?pId, IpData pData, string pIpAddress, Reference pLocale, int?pLocaleId) : base(pId, pData, pIpAddress, pLocale, pLocaleId) { }
public void SetCurServer() { string[] info = IpData.GetCurServerData(); curServerIndexLabel.text = info[0]; curServerNameLabel.text = info[3]; }