shodan 0.2.0.0 → 0.3.0.0
raw patch · 7 files changed
+41/−17 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Shodan: [matchVersion] :: SearchMatch -> Maybe Text
- Shodan: SearchMatch :: Text -> Int -> Maybe Text -> Maybe Text -> SearchMatch
+ Shodan: SearchMatch :: Text -> Int -> Maybe Text -> Maybe Text -> Maybe Text -> SearchMatch
Files
- CHANGELOG.md +16/−1
- README.md +6/−6
- examples/search/Main.hs +2/−1
- shodan.cabal +1/−1
- src/Shodan.hs +4/−1
- test/Main.hs +1/−1
- test/SearchTests.hs +11/−6
CHANGELOG.md view
@@ -2,7 +2,22 @@ This package follows the [Haskell Package Versioning Policy](https://pvp.haskell.org/). -## 0.2.0.0 — Unreleased+## 0.3.0.0 — 2026-11-20++### Breaking changes++- Added `matchVersion :: Maybe Text` to `SearchMatch`, changing its constructor+ arity. Update positional constructor calls and patterns for the new field+ between product and ASN. This datatype change requires a PVP major bump.++### Additions++- Parse the optional Shodan `version` string; missing or null values become+ `Nothing`, and non-text values are rejected.+- Display a `VERSION` column in `shodan-search`, using `-` when unavailable.+- Test present, absent, null, and invalid version values.++## 0.2.0.0 — 2026-11-20 ### Breaking changes
README.md view
@@ -4,8 +4,8 @@ Licensed under the [BSD 3-Clause License](LICENSE). -Version **0.2.0.0** is being prepared for release. See the [changelog](CHANGELOG.md)-for additions and the `ShodanError` constructor change requiring a PVP major bump.+Current version: **0.3.0.0**. See the [changelog](CHANGELOG.md)+for additions and the `SearchMatch` constructor change requiring a PVP major bump. This project supports `GET /api-info` (`ApiInfo` and `UsageLimits`), `GET /shodan/host/count` (`CountResult`), and one-page@@ -113,7 +113,7 @@ Both fields are required. Unknown fields are ignored, while missing fields, invalid counts, and non-object buckets are rejected. -## Search (0.2.0.0, unreleased)+## Search Version 0.2.0.0 adds one-page searches: @@ -138,11 +138,11 @@ page after the first uses a credit under the [official API policy](https://developer.shodan.io/api). The example prints the total across all pages, the selected page number, the returned service count, and a table of-IP, port, product, and ASN. Missing product/ASN values are displayed as `-`.+IP, port, product, version, and ASN. Missing product/version/ASN values are displayed as `-`. `SearchMatch` describes one matching service with `matchIp`, `matchPort`,-`matchProduct`, and `matchAsn`. IP text and an integer port from 0 through 65535-are required. Product and ASN are optional: missing or null values become+`matchProduct`, `matchVersion`, and `matchAsn`. IP text and an integer port from 0 through 65535+are required. Product, version, and ASN are optional: missing or null values become `Nothing`, while other non-text values are rejected. IP syntax is not validated. Unknown banner fields are ignored.
examples/search/Main.hs view
@@ -27,7 +27,7 @@ putStrLn ("Total: " ++ show (searchTotal found)) putStrLn ("Page: " ++ show page) putStrLn ("Returned: " ++ show (length (searchMatches found)))- putStrLn "IP\tPORT\tPRODUCT\tASN"+ putStrLn "IP\tPORT\tPRODUCT\tVERSION\tASN" mapM_ printMatch (searchMatches found) parseArguments :: [String] -> IO (Text.Text, Int)@@ -44,5 +44,6 @@ [ Text.unpack (matchIp match) , show (matchPort match) , maybe "-" Text.unpack (matchProduct match)+ , maybe "-" Text.unpack (matchVersion match) , maybe "-" Text.unpack (matchAsn match) ])
shodan.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: shodan-version: 0.2.0.0+version: 0.3.0.0 license: BSD-3-Clause license-file: LICENSE synopsis: A simple Haskell client for the Shodan API
src/Shodan.hs view
@@ -130,6 +130,8 @@ -- ^ Required integer port, from 0 through 65535. , matchProduct :: Maybe Text -- ^ Detected product; absent or null means 'Nothing'.+ , matchVersion :: Maybe Text+ -- ^ Detected product version; absent or null means 'Nothing'. , matchAsn :: Maybe Text -- ^ ASN such as @AS65536@; absent or null means 'Nothing'. } deriving (Eq, Show)@@ -139,10 +141,11 @@ ip <- o .: "ip_str" port <- o .: "port" productName <- o .:? "product"+ version <- o .:? "version" asn <- o .:? "asn" if port < 0 || port > 65535 then fail "Search match port must be between 0 and 65535"- else pure (SearchMatch ip port productName asn)+ else pure (SearchMatch ip port productName version asn) -- | One page returned by @GET /shodan/host/search@. -- The total covers the whole query and may exceed this page's match count.
test/Main.hs view
@@ -188,7 +188,7 @@ query = "http.title:\"한글 + & ?\" product:nginx" responseBody = "{\"total\":101,\"matches\":[{\"ip_str\":\"192.0.2.1\",\"port\":443,\"product\":\"nginx\",\"asn\":\"AS65536\"}]}" expected = Right (SearchResult 101- [SearchMatch "192.0.2.1" 443 (Just "nginx") (Just "AS65536")] Map.empty)+ [SearchMatch "192.0.2.1" 443 (Just "nginx") Nothing (Just "AS65536")] Map.empty) application page request respond = do check "search GET" (Wai.requestMethod request == "GET") check "search path" (Wai.pathInfo request == ["shodan", "host", "search"])
test/SearchTests.hs view
@@ -12,7 +12,7 @@ searchParsingTests = do -- Selected fields from the official GET /shodan/host/search example. -- Source: https://developer.shodan.io/api- let match = SearchMatch "96.93.212.27" 443 (Just "nginx") (Just "AS7922")+ let match = SearchMatch "96.93.212.27" 443 (Just "nginx") Nothing (Just "AS7922") expected = SearchResult 23047224 [match] (Map.singleton "country" [Facet (String "US") 7883733]) example = "{\"total\":23047224,\"matches\":[{\"ip_str\":\"96.93.212.27\",\"port\":443,\"product\":\"nginx\",\"asn\":\"AS7922\",\"http\":{\"server\":\"nginx\"}}],\"facets\":{\"country\":[{\"value\":\"US\",\"count\":7883733}]}}"@@ -22,17 +22,20 @@ check "total can exceed page size" (eitherDecode' "{\"total\":100000000000000000000,\"matches\":[],\"future\":true}" == Right (SearchResult 100000000000000000000 [] Map.empty))- let minimal = SearchMatch "2001:db8::1" 0 Nothing Nothing+ check "product version" (eitherDecode'+ "{\"ip_str\":\"192.0.2.1\",\"port\":443,\"product\":\"nginx\",\"version\":\"1.26.2\"}" ==+ Right (SearchMatch "192.0.2.1" 443 (Just "nginx") (Just "1.26.2") Nothing))+ let minimal = SearchMatch "2001:db8::1" 0 Nothing Nothing Nothing check "IPv6 and absent optional fields" (eitherDecode' "{\"ip_str\":\"2001:db8::1\",\"port\":0}" == Right minimal) check "null optional fields and maximum port" (eitherDecode'- "{\"ip_str\":\"192.0.2.1\",\"port\":65535,\"product\":null,\"asn\":null}" ==- Right (SearchMatch "192.0.2.1" 65535 Nothing Nothing))+ "{\"ip_str\":\"192.0.2.1\",\"port\":65535,\"product\":null,\"version\":null,\"asn\":null}" ==+ Right (SearchMatch "192.0.2.1" 65535 Nothing Nothing Nothing)) let twoMatches = "{\"total\":2,\"matches\":[{\"ip_str\":\"192.0.2.1\",\"port\":80},{\"ip_str\":\"192.0.2.1\",\"port\":443}],\"facets\":{}}" check "multiple services on one IP retain order" (eitherDecode' twoMatches == Right (SearchResult 2- [SearchMatch "192.0.2.1" 80 Nothing Nothing,- SearchMatch "192.0.2.1" 443 Nothing Nothing] Map.empty))+ [SearchMatch "192.0.2.1" 80 Nothing Nothing Nothing,+ SearchMatch "192.0.2.1" 443 Nothing Nothing Nothing] Map.empty)) mapM_ rejectsMatch [ ("missing IP", "{\"port\":443}") , ("null IP", "{\"ip_str\":null,\"port\":443}")@@ -43,6 +46,8 @@ , ("negative port", "{\"ip_str\":\"192.0.2.1\",\"port\":-1}") , ("out-of-range port", "{\"ip_str\":\"192.0.2.1\",\"port\":65536}") , ("wrong product type", "{\"ip_str\":\"192.0.2.1\",\"port\":443,\"product\":true}")+ , ("numeric version", "{\"ip_str\":\"192.0.2.1\",\"port\":443,\"version\":126}")+ , ("object version", "{\"ip_str\":\"192.0.2.1\",\"port\":443,\"version\":{}}") , ("wrong ASN type", "{\"ip_str\":\"192.0.2.1\",\"port\":443,\"asn\":65536}") , ("non-object match", "[]") ]