예제 #1
0
        private static async Task <IsItInTheCloudResult> IsItInTheCloud(string lookup, CloudTable table)
        {
            var(ip, host) = await IpUtils.IpFromUnknownInput(lookup);

            string partitionKey   = ip.AddressFamily == AddressFamily.InterNetwork ? "ipv4" : "ipv6";
            var    paddedIp       = IpUtils.IpToPaddedDecimal(ip.ToString());
            var    pkFilter       = TableQuery.GenerateFilterCondition(nameof(IPAddressEntity.PartitionKey), QueryComparisons.Equal, partitionKey);
            var    rkFilter       = TableQuery.GenerateFilterCondition(nameof(IPAddressEntity.RowKey), QueryComparisons.GreaterThanOrEqual, paddedIp);
            var    combinedFilter = TableQuery.CombineFilters(pkFilter, TableOperators.And, rkFilter);

            var query = new TableQuery <IPAddressEntity>
            {
                TakeCount    = 1,
                FilterString = combinedFilter
            };

            var querySegment = await table.ExecuteQuerySegmentedAsync(query, null);

            var entity = querySegment.SingleOrDefault();

            return(new IsItInTheCloudResult
            {
                HostName = host,
                Ip = ip.ToString(),
                Match = (entity == null || string.Compare(entity.LowerRange, paddedIp, StringComparison.Ordinal) > 0)
                    ? null
                    : entity
            });
        }
예제 #2
0
        public IPAddressEntity(string platform, string region, string service, string cidr)
        {
            var ip         = IPNetwork.Parse(cidr);
            var lowerRange = IpUtils.IpToPaddedDecimal(ip.FirstUsable.ToString());
            var upperRange = IpUtils.IpToPaddedDecimal(ip.LastUsable.ToString());

            var partitionKey = ip.AddressFamily == AddressFamily.InterNetwork ? IPv4PartitionKey : IPv6PartitionKey;

            PartitionKey = partitionKey;
            RowKey       = upperRange;
            LowerRange   = lowerRange;
            Platform     = platform;
            Region       = region;
            Service      = service;
            CIDR         = cidr;
        }