Shodan 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Shodan --version 1.0.1                
NuGet\Install-Package Shodan -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Shodan" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Shodan --version 1.0.1                
#r "nuget: Shodan, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Shodan as a Cake Addin
#addin nuget:?package=Shodan&version=1.0.1

// Install Shodan as a Cake Tool
#tool nuget:?package=Shodan&version=1.0.1                

Intro

This library is an asynchronous C# client for shodan.io REST API.

Features

The main feature of this library is a rich models - they contain a lot of properties, which other libraries just not aware of. For example, Service object has the following properties with valueable information (if such services were detected on host, of course - otherwise they will just have null value):

  • Cassandra
  • DB2
  • DNS
  • Docker
  • Elastic
  • Etcd
  • EthernetIP
  • FTP
  • Hive
  • HTTP
  • ISAKMP
  • Lantronix
  • Monero
  • MongoDB
  • MQTT
  • Netbios
  • NTP
  • Redis
  • RIP
  • Rsync
  • SMB
  • SNMP
  • SSH
  • Vertx

All models and their complex properties also has ExtraValues property for an unknown keys in response.

The second feature, which makes this library unique, is a set of methods - all API is covered, including exploits and stream. There are even methods, that are not listed in documentantion - like ListScans() and Services()

Third feature is a search query classes, which allows you to create query as CLR object, modify and even serialize it. The object is mutable, so you can, for example, increase a page in search parameters. Of course, such approach has its own limitations, that's why you can always use just a string for performing search.

Also, because of very big set of API methods, there are separate client classes for exploits, stream and alerts APIs. You can use them by themselves or acces via ShodanClient class properties.

Basic usage example

This example shows how to create a client, compose a search query and how to use models later.

    class Program
    {
        static async Task Main()
        {
            string key = Environment.GetEnvironmentVariable("SHODAN_API_KEY");

            ShodanClient client = new ClientFactory(key).GetFullClient();

            // All client methods are asynchronous;
            // The only exception is StreamClient, which has generator methods.
            ApiInfo apiInfo = await client.ApiInfo();
            Console.WriteLine("Unlocked credits left: {0}", apiInfo.UnlockedLeft);

            // Some other clients are properties of full client
            var alerts = await client.Alerts.ListAlerts();

            // You can create a query object for search or just pass a string to search method;
            // Fill "Text" property of query to specify a search term.
            ShodanSearchQuery query = new ShodanSearchQuery
            {
                // We want to find exposed ElasticSearch instances in China with a "readme" index
                // (typically it's an index with ransom note)
                Text = "readme",
                Country = "CN",
                Port = 9200
            };

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(query.Parameters.Page);
                query.Parameters.Page++;

                SearchResult result = await client.Search(query);

                PrintElasticsInfo(result);
                query.Parameters.Page++; // ShodanSearchQuery object is mutable

                if (result.Services.Count < 100)
                    break;
            }

            Console.ReadLine();
        }

        // This method prints some of ElasicSearch properties to stdout
        private static void PrintElasticsInfo(SearchResult result)
        {
            foreach (Service service in result.Services.Where(s => s.Elastic != null))
            {
                var elastic = service.Elastic;

                // you should be careful about nulls - Shodan responses are not statically typed and can lack some keys
                if (elastic.Cluster?.Indices?.Count > 0 && elastic.Cluster?.Indices?.Docs?.Count > 0)
                {
                    Console.WriteLine($"Exposed ElasticSearch at {service.IPStr}:{service.Port}");
                    Console.WriteLine($"Total docs: {elastic.Cluster.Indices.Docs.Count}");
                    Console.WriteLine($"Total bytes: {elastic.Cluster.Indices.Store?.SizeInBytes}");
                    Console.WriteLine($"Cluster name: {elastic.Cluster.ClusterName}");

                    Console.WriteLine("Indices:");
                    foreach (string indexName in elastic.Indices.Keys)
                    {
                        Console.WriteLine($"\t{indexName}");
                    }
                }
                Console.WriteLine();
            }
        }
    }

Since version 1.0.0 library supports Microsoft dependency injection. For example, in ASP.NET project you can register all available clients in your Startup.cs in ConfigureServices method like this:


        using Shodan.Extensions;  // namespace with DI extensions

        ...

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddShodanClients(Environment.GetEnvironmentVariable("SHODAN_API_KEY"));
        }

Now you can create your services with any client type as dependency.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.3 3,860 12/19/2023
2.0.2 12,051 2/10/2021
2.0.1 636 5/5/2020
2.0.0 474 4/22/2020
1.0.2 522 3/18/2020
1.0.1 490 2/7/2020
1.0.0 509 1/14/2020
0.2.0 519 1/9/2020
0.1.9 557 1/7/2020
0.1.8 448 12/25/2019
0.1.7 490 12/14/2019
0.1.6 508 10/23/2019
0.1.5 467 10/17/2019
0.1.4 472 10/16/2019
0.1.3 504 9/14/2019
0.1.2 503 9/12/2019
0.1.1 494 9/1/2019
0.1.0 534 8/24/2019

added CancellationToken support