From bbb863a5ea331704921d326da973084b899f6cc7 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Wed, 1 Jun 2016 19:15:11 -0400 Subject: [PATCH] stopping for now --- src/Shodan.Net.UnitTests/Class1.cs | 19 -------- .../Intergration/TestSuite.cs | 25 ++++++++++ src/Shodan.Net.UnitTests/project.json | 3 +- src/Shodan.Net/Models/Certificate.cs | 47 +++++++++++++++++++ src/Shodan.Net/Models/Host.cs | 1 - src/Shodan.Net/Models/SearchHostResults.cs | 1 - src/Shodan.Net/Models/SslProperties.cs | 8 +++- src/Shodan.Net/Net/RequestHandler.cs | 2 +- src/Shodan.Net/Search/QueryGenerator.cs | 2 +- src/Shodan.Net/ShodanClient.cs | 4 +- src/Shodan.Net/project.json | 2 +- 11 files changed, 85 insertions(+), 29 deletions(-) delete mode 100644 src/Shodan.Net.UnitTests/Class1.cs create mode 100644 src/Shodan.Net.UnitTests/Intergration/TestSuite.cs create mode 100644 src/Shodan.Net/Models/Certificate.cs diff --git a/src/Shodan.Net.UnitTests/Class1.cs b/src/Shodan.Net.UnitTests/Class1.cs deleted file mode 100644 index aff00da..0000000 --- a/src/Shodan.Net.UnitTests/Class1.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Xunit; - -namespace Shodan.Net.UnitTests -{ - // This project can output the Class library as a NuGet Package. - // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". - public class Class1 - { - [Fact] - public void privateGetsPorts() - - { - } - } -} \ No newline at end of file diff --git a/src/Shodan.Net.UnitTests/Intergration/TestSuite.cs b/src/Shodan.Net.UnitTests/Intergration/TestSuite.cs new file mode 100644 index 0000000..271d572 --- /dev/null +++ b/src/Shodan.Net.UnitTests/Intergration/TestSuite.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace Shodan.Net.UnitTests.Intergration +{ + public class TestSuite + { + private readonly ShodanClient shodanClient = new ShodanClient("9F0mxmNSaHbe0mYmefwoCZrChT2h0KzC"); + + [Fact] + public async Task GetHost() + { + var result = await shodanClient.GetHostAsync("41.21.249.170"); + } + + [Fact] + public async Task PerformSearch() + { + var result = await shodanClient.SearchHosts(a => a.With_state("NY")); + } + } +} \ No newline at end of file diff --git a/src/Shodan.Net.UnitTests/project.json b/src/Shodan.Net.UnitTests/project.json index 55d51cb..ad9949a 100644 --- a/src/Shodan.Net.UnitTests/project.json +++ b/src/Shodan.Net.UnitTests/project.json @@ -5,7 +5,8 @@ "NETStandard.Library": "1.5.0-rc2-24027", "xunit": "2.1.0", "dotnet-test-xunit": "1.0.0-rc2-build10015", - "Shodan.Net": "1.0.0-*" + "Shodan.Net": "1.0.0-*", + "Newtonsoft.Json": "8.0.3" }, "frameworks": { diff --git a/src/Shodan.Net/Models/Certificate.cs b/src/Shodan.Net/Models/Certificate.cs new file mode 100644 index 0000000..c0e8483 --- /dev/null +++ b/src/Shodan.Net/Models/Certificate.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Threading.Tasks; + +namespace Shodan.Net.Models +{ + public class Certificate + { + [DataMember(Name = "sig_alg")] + public string SignatureAlgorithmm { get; set; } + + [DataMember(Name = "issued")] + public string Issued { get; set; } + + [DataMember(Name = "expires")] + public DateTime Expires { get; set; } + + [DataMember(Name = "expired")] + public bool Expired { get; set; } + + [DataMember(Name = "version")] + public int Version { get; set; } + + [DataMember(Name = "fingerprint")] + public Fingerprint Fingerprint { get; set; } + + [DataMember(Name = "subject")] + public dynamic Subject { get; set; } + + [DataMember(Name = "pubkey")] + public dynamic PublicKey { get; set; } + + [DataMember(Name = "issuer")] + public dynamic Issuer { get; set; } + + [DataMember(Name = "ciper")] + public dynamic Ciper { get; set; } + } + + public class Fingerprint + { + public string sha256 { get; set; } + public string sha1 { get; set; } + } +} \ No newline at end of file diff --git a/src/Shodan.Net/Models/Host.cs b/src/Shodan.Net/Models/Host.cs index a064d96..371cf0c 100644 --- a/src/Shodan.Net/Models/Host.cs +++ b/src/Shodan.Net/Models/Host.cs @@ -36,7 +36,6 @@ namespace Shodan.Net.Models [DataMember(Name = "country_code")] public string CountryCode { get; set; } - [DataMember(Name = "data")] public List Data { get; set; } [DataMember(Name = "city")] diff --git a/src/Shodan.Net/Models/SearchHostResults.cs b/src/Shodan.Net/Models/SearchHostResults.cs index cd32a99..a035d92 100644 --- a/src/Shodan.Net/Models/SearchHostResults.cs +++ b/src/Shodan.Net/Models/SearchHostResults.cs @@ -12,7 +12,6 @@ namespace Shodan.Net.Models [DataContract] public class SearchHostResults { - [DataMember(Name = "matches")] public List Matches { get; set; } [DataMember(Name = "facets")] diff --git a/src/Shodan.Net/Models/SslProperties.cs b/src/Shodan.Net/Models/SslProperties.cs index 3873fba..b39b332 100644 --- a/src/Shodan.Net/Models/SslProperties.cs +++ b/src/Shodan.Net/Models/SslProperties.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; @@ -13,7 +14,10 @@ namespace Shodan.Net.Models /// The parsed certificate properties that includes information such as when it was issued, the SSL extensions, the issuer, subject etc. /// [DataMember(Name = "cert")] - public dynamic Cert { get; set; } + public Certificate Cert { get; set; } + + [IgnoreDataMember] + public decimal[] Serial { get; set; } /// /// Preferred cipher for the SSL connection diff --git a/src/Shodan.Net/Net/RequestHandler.cs b/src/Shodan.Net/Net/RequestHandler.cs index ee6dcea..3099bb0 100644 --- a/src/Shodan.Net/Net/RequestHandler.cs +++ b/src/Shodan.Net/Net/RequestHandler.cs @@ -13,7 +13,7 @@ namespace Shodan.Net /// public class RequestHandler : IRequstHandler { - private HttpClient client { get; set; } + private HttpClient client = new HttpClient(); public async Task MakeRequestAsync(Uri url, HttpContent content = null, RequestType requstType = RequestType.GET) where T : class diff --git a/src/Shodan.Net/Search/QueryGenerator.cs b/src/Shodan.Net/Search/QueryGenerator.cs index 968547b..f06ce61 100644 --- a/src/Shodan.Net/Search/QueryGenerator.cs +++ b/src/Shodan.Net/Search/QueryGenerator.cs @@ -8,7 +8,7 @@ namespace Shodan.Net { public class QueryGenerator { - internal Dictionary queryData { get; set; } + internal Dictionary queryData = new Dictionary(); private HashSet CalledMethods = new HashSet(); private string searchText = string.Empty; diff --git a/src/Shodan.Net/ShodanClient.cs b/src/Shodan.Net/ShodanClient.cs index 809cbab..e2149c0 100644 --- a/src/Shodan.Net/ShodanClient.cs +++ b/src/Shodan.Net/ShodanClient.cs @@ -63,7 +63,7 @@ namespace Shodan.Net /// The page number to page through results 100 at a time (default: 1) /// True or False; whether or not to truncate some of the larger fields (default: True) /// - public Task SearchHosts(Action query, Action facet = null, int page = 1, bool minify = true) + public Task SearchHosts(Action query, Action facet = null, int page = 1, bool minify = true) { if(query == null) { @@ -86,7 +86,7 @@ namespace Shodan.Net { url.Query = $"{url.Query}&page={page}"; } - return RequestHandler.MakeRequestAsync(url.Uri); + return RequestHandler.MakeRequestAsync(url.Uri); } /// diff --git a/src/Shodan.Net/project.json b/src/Shodan.Net/project.json index c7e9002..bed2e56 100644 --- a/src/Shodan.Net/project.json +++ b/src/Shodan.Net/project.json @@ -1,5 +1,5 @@ { - "version": "0.2.0", + "version": "0.3.0", "authors": [ "Tommy Parnell" ], "dependencies": {