Skip to content

Convenient functions for working with Azure IP networks

License

Notifications You must be signed in to change notification settings

mburumaxwell/AzureIPNetworks

Repository files navigation

AzureIPNetworks

NuGet Nuget

Introduction

This library eases working with known Azure IP networks in dotnet. AzureCloudServiceTag provides the IP ranges for the entire cloud and is also broken out by region within that cloud. You cannot create your own service tag nor can you specify which IP addresses are included within a tag. Microsoft manages the address prefixes encompassed by the service tag, and automatically updates the service tag and their addresses as they change.

Service tags are stored in a JSON file which contains the IP address ranges for Public Azure as a whole, each Azure region within Public, and ranges for several Azure services such as EventHub, KeyVault, Storage, SQL, and TrafficManager in Public. The JSON file is downloaded from Microsoft's Website every so often from:

The library offers capabilities such as:

  • Listing IP addresses or IP networks used by the whole of Azure or filtered to a single service tag.
  • Checking if a given IP address or IP network belongs to Azure

The current version of the files can be found at files.json

You can also download the files from the remote URL once per application run using AzureIPsProvider.Remote.xxxx methods

Installation

Using the .NET Core command-line interface (CLI) tools:

dotnet add package AzureIPNetworks

Using the NuGet Command Line Interface (CLI):

nuget install AzureIPNetworks

Using the Package Manager Console:

Install-Package AzureIPNetworks

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on a project within your solution.
  3. Click on Manage NuGet Packages...
  4. Click on the Browse tab and search for "AzureIPNetworks".
  5. Click on the AzureIPNetworks package, select the appropriate version in the right-tab and click Install.

Example 1 - Get all IP Networks (local)

var networks = await AzureIPsProvider.Local.GetNetworksAsync(AzureCloud.Public);
foreach (var net in networks)
{
    Console.WriteLine($"{net} ({range.FirstUsable} to {net.LastUsable})");
}

Example 2 - Check if an IP is used by Azure (local)

var ip = "30.0.0.20";
var used = await AzureIPsProvider.Local.IsAzureIpAsync(IPAddress.Parse(ip));
Console.WriteLine($"{ip} is {(used ? "" : "not")} used by any Azure service");

Example 3 - Get all IP Networks (remote)

var networks = await AzureIPsProvider.Remote.GetNetworksAsync(AzureCloud.Public);
foreach (var net in networks)
{
    Console.WriteLine($"{net} ({range.FirstUsable} to {net.LastUsable})");
}

Example 4 - Check if an IP is used by Azure (remote)

var ip = "30.0.0.20";
var used = await AzureIPsProvider.Remote.IsAzureIpAsync(IPAddress.Parse(ip));
Console.WriteLine($"{ip} is {(used ? "" : "not")} used by any Azure service");

Issues & Comments

Please leave all comments, bugs, requests, and issues on the Issues page. We'll respond to your request ASAP!

License

The Library is licensed under the MIT license. Refer to the LICENSE file for more information.

About

Convenient functions for working with Azure IP networks

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages