<commit_before>﻿using System.Web.Http;
using System.Web.Routing;
using SH.ShowYou.Helpers;
using System.Net;

namespace SH.ShowYou.Controllers
{
    public class GeoController : ApiControllerBase
    {
        [Route("geo")]
        [HttpGet]
        public IHttpActionResult Get(string ip = "")
        {
            if (string.IsNullOrEmpty(ip))
            {
                ip = GetIpAddress();
            }

            if (string.IsNullOrEmpty(ip))
            {
                return BadRequest();
            }            

            var geoLiteCityLocation = CsvDatabaseHelpers.GetGeoLiteCityLocation(ip);

            return Ok(geoLiteCityLocation);
        }
    }
}
<commit_msg>Update validate ip address<commit_after>﻿using System.Web.Http;
using System.Web.Routing;
using SH.ShowYou.Helpers;
using System.Net;

namespace SH.ShowYou.Controllers
{
    public class GeoController : ApiControllerBase
    {
        [Route("geo")]
        [HttpGet]
        public IHttpActionResult Get(string ip = "")
        {
            if (string.IsNullOrEmpty(ip))
            {
                ip = GetIpAddress();
            }

            IPAddress ipAddress;
            if (string.IsNullOrEmpty(ip) || IPAddress.TryParse(ip, out ipAddress))
            {
                return BadRequest("Invalid ip address");
            }            

            var geoLiteCityLocation = CsvDatabaseHelpers.GetGeoLiteCityLocation(ip);

            return Ok(geoLiteCityLocation);
        }
    }
}

{'fraction_non_alphanumeric': 0.09431438127090301, 'fraction_numerical': 0.0, 'mean_word_length': 1.7858472998137802, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5549422', 'n_tokens_mistral': 412, 'n_tokens_neox': 415, 'n_words': 76}