Skip to content
  • English Deutsch

benjamin-abt.com

Performance is a feature | Cloud - AI - Azure - .NET - Sustainability

  • Home
  • Blog
  • Portfolio
    • Overview
    • Workshops & Training
    • Publications
  • Contact
  • Home
  • Blog

Load Google Search Crawler IP Address Ranges with Refit

Load Google Search Crawler IP Address Ranges with Refit
December 3, 2024 3 min read BEN ABT
Csharp .NET

Rate Limit is a great tool to protect your own website and content from misuse; in some cases, however, rate limiting is also bad: for example, if you want your own content to be indexed by Google Search in order to increase your own visibility.

According to the documentation , Google offers various options for this; however, the most secure is the recognition of the search crawler by the IP address, as this is virtually impossible to falsify or can only be falsified with a great deal of effort.

Google Bot Json

Google offers a static Json file for this purpose, in which Google regularly publishes the IP address ranges used by the search crawl bots. The Json format has a basic structure that looks like this:

JSON
1 "creationTime": "2024-11-26T15:46:03.000000",
2    "prefixes": [
3        {
4            "ipv6Prefix": "2001:4860:4801:10::/64"
5        },

where besides ipv6Prefix also ipv4Prefix can be defined.

This json can be defined very easily as C# record classes:

C#
1public sealed record class GoogleSearchCrawlerIPAddressResult(
2    [property: JsonPropertyName("creationTime")] DateTimeOffset CreationTime,
3    [property: JsonPropertyName("prefixes")] List<GoogleSearchCrawlerIPAddressRangeItem> IPRanges);
4
5public sealed record class GoogleSearchCrawlerIPAddressRangeItem(
6     [property: JsonPropertyName("ipv6Prefix")] string? IPv6,
7     [property: JsonPropertyName("ipv4Prefix")] string? IPv4);

Refit

To make this as easy as possible to consume using C#, Refit is a good option.

To do this, Refit must be stored as a NuGet package in the project files.

XML
 1<Project Sdk="Microsoft.NET.Sdk">
 2
 3  <PropertyGroup>
 4    <OutputType>Exe</OutputType>
 5    <TargetFramework>net9.0</TargetFramework>
 6    <ImplicitUsings>enable</ImplicitUsings>
 7    <Nullable>enable</Nullable>
 8  </PropertyGroup>
 9
10  <ItemGroup>
11    <PackageReference Include="Refit" Version="8.0.0" />
12  </ItemGroup>
13
14</Project>

A refit interface can then be created with the end point:

C#
1public interface IGoogleSearchCrawlerIPAddressRangesHttpClient
2{
3    [Get("/static/search/apis/ipranges/googlebot.json")]
4    Task<GoogleSearchCrawlerIPAddressResult> GetRanges(CancellationToken cancellationToken);
5}

We can now use the interface to create an instance with Refit and load data:

C#
1IGoogleSearchCrawlerIPAddressRangesHttpClient googleSearchBotIPAddressClient = RestService
2    .For<IGoogleSearchCrawlerIPAddressRangesHttpClient>("https://developers.google.com");
3
4GoogleSearchCrawlerIPAddressResult result = await googleSearchBotIPAddressClient.GetRanges(CancellationToken.None);

You can now work with the data; for example, simply output it:

C#
 1foreach (GoogleSearchCrawlerIPAddressRangeItem entry in result.IPRanges)
 2{
 3    if (entry.IPv4 is not null)
 4    {
 5        Console.WriteLine($"> Found IPv4 range: {entry.IPv4}");
 6    }
 7    if (entry.IPv6 is not null)
 8    {
 9        Console.WriteLine($"> Found IPv6 range: {entry.IPv6}");
10    }
11}

Full example:

C#
 1using System.Text.Json.Serialization;
 2using Refit;
 3
 4Console.WriteLine("Loading IP Addresses from Google Search Bot Json");
 5
 6IGoogleSearchCrawlerIPAddressRangesHttpClient googleSearchBotIPAddressClient = RestService
 7    .For<IGoogleSearchCrawlerIPAddressRangesHttpClient>("https://developers.google.com");
 8
 9GoogleSearchCrawlerIPAddressResult result = await googleSearchBotIPAddressClient.GetRanges(CancellationToken.None);
10
11Console.WriteLine($"Found {result.IPRanges.Count} entries from {result.CreationTime:o}.");
12
13foreach (GoogleSearchCrawlerIPAddressRangeItem entry in result.IPRanges)
14{
15    if (entry.IPv4 is not null)
16    {
17        Console.WriteLine($"> Found IPv4 range: {entry.IPv4}");
18    }
19    if (entry.IPv6 is not null)
20    {
21        Console.WriteLine($"> Found IPv6 range: {entry.IPv6}");
22    }
23}
24
25Console.WriteLine("Finished.");
26
27
28// Refit definition
29
30public interface IGoogleSearchCrawlerIPAddressRangesHttpClient
31{
32    [Get("/static/search/apis/ipranges/googlebot.json")]
33    Task<GoogleSearchCrawlerIPAddressResult> GetRanges(CancellationToken cancellationToken);
34}
35
36public sealed record class GoogleSearchCrawlerIPAddressResult(
37    [property: JsonPropertyName("creationTime")] DateTimeOffset CreationTime,
38    [property: JsonPropertyName("prefixes")] List<GoogleSearchCrawlerIPAddressRangeItem> IPRanges);
39
40public sealed record class GoogleSearchCrawlerIPAddressRangeItem(
41     [property: JsonPropertyName("ipv6Prefix")] string? IPv6,
42     [property: JsonPropertyName("ipv4Prefix")] string? IPv4);

Related articles

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026 - 11 min read

Containerizing .NET in 2026 Without a Dockerfile

Most .NET Dockerfiles repeat the same five steps: restore, publish, select the matching Microsoft runtime image, copy the output and start …

Problem Details in ASP.NET Core and .NET 11

Oct 5, 2026 - 12 min read

Problem Details in ASP.NET Core and .NET 11

builder.Services.AddProblemDetails() registers infrastructure. It does not create an error contract. An ASP.NET Core request can fail during …

Resilience in .NET with Microsoft.Extensions.Resilience

Sep 21, 2026 - 11 min read

Resilience in .NET with Microsoft.Extensions.Resilience

Retries are the most visible resilience strategy and the easiest one to misuse. Repeating a failing call can recover from a short network …


BEN ABT

BEN ABT

Ben is Chief Engineering Officer and Principal Software Engineer at Medialesson.de, with a strong focus on .NET and Microsoft Azure. In his professional role, he designs and builds highly scalable platforms for hybrid and cloud-based scenarios. He also advises companies and C-levels on migrating to the sovereign cloud.

He runs myCSharp.de, the largest and most active German-speaking C# community forum, actively contributes to both his own and external open-source projects and regularly shares his knowledge through his blog, at community events, conferences and as a writer for technical magazines.

Let's Work Together

Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

New Platforms

Modernization

Training & Consulting

Contact Me
X Facebook LinkedIn WhatsApp
Back Next Blog Post

Open for work!

Contact Me
BEN ABT BEN ABT Software Engineer · Microsoft MVP Passionate about .NET, Azure, performance optimization and sustainable software engineering.

Medialesson GmbH Logo

Microsoft MVP Logo

Recent posts

View all
Stop Using nginx as Your Default Static File Server in Docker

Stop Using nginx as Your Default Static File Server in …

Oct 24, 2026
Containerizing .NET in 2026 Without a Dockerfile

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026
Problem Details in ASP.NET Core and .NET 11

Problem Details in ASP.NET Core and .NET 11

Oct 5, 2026
Resilience in .NET with Microsoft.Extensions.Resilience

Resilience in .NET with Microsoft.Extensions.Resilience

Sep 21, 2026
What Matters in ASP.NET Core 11

What Matters in ASP.NET Core 11

Sep 14, 2026

Tags

.NET (192) Csharp (96) ASP.NET Core (48) Azure (41) DevOps (17) Docker (14) Microsoft (14) EF Core (11) Microsoft MVP (11) AI (10) GitHub (10) GitHub Copilot (10) ASP.NET (9) Security (9) Synology (9) Architecture (8) Raspberry (8) Azure Functions (7) Cloudflare (7) Bicep (6)
benjamin-abt.com

About BEN

Benjamin Abt is a Software Engineer, Platform Architect and Microsoft MVP specializing in .NET, Azure, cloud architecture, performance optimization and sustainable software development.

Connect

  • Follow me on GitHub
  • Follow me on LinkedIn
  • Follow me on Mastodon
  • Microsoft MVP profile
  • Follow SchwabenCode on GitHub
  • Follow me on X

Quick Links

  • Portfolio
  • Blog
  • Workshops & Training
  • Publications
  • Get in Touch
  • Sitemap
Open for Work

© Copyright Benjamin Abt & SchwabenCode | 2011 - 2026

Content licensed under CC BY 4.0 unless otherwise noted.

  • Impressum
  • Privacy
  • Contact