Skip to content

Commit

Permalink
hotfix api
Browse files Browse the repository at this point in the history
  • Loading branch information
incogbyte committed Oct 5, 2024
1 parent 9cf4320 commit 440e20a
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions apishodan/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apishodan
import (
"encoding/json"
"fmt"
"io"
"net/http"
)

Expand Down Expand Up @@ -41,31 +42,31 @@ func New(key string) *API {
}

func (s *API) InfoAccount() (*JsonData, error) {
res, err := http.Get(fmt.Sprintf("%s/api-info?key=%s", URL, s.apiKey))
if err != nil {
return nil, fmt.Errorf("failed to make request ( Info Account Shodan ): %v", err)
}
defer res.Body.Close()

if res.StatusCode == http.StatusUnauthorized {
return nil, fmt.Errorf("authorization error: invalid Shodan API key (HTTP 401)")
}

if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", res.StatusCode)
}

body, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %v", err)
}

var ret JsonData
if err := json.Unmarshal(body, &ret); err != nil {
return nil, fmt.Errorf("failed to decode JSON response: %v", err)
}

return &ret, nil
res, err := http.Get(fmt.Sprintf("%s/api-info?key=%s", URL, s.apiKey))
if err != nil {
return nil, fmt.Errorf("failed to make request ( Info Account Shodan ): %v", err)
}
defer res.Body.Close()

if res.StatusCode == http.StatusUnauthorized {
return nil, fmt.Errorf("authorization error: invalid Shodan API key (HTTP 401)")
}

if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", res.StatusCode)
}

body, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %v", err)
}

var ret JsonData
if err := json.Unmarshal(body, &ret); err != nil {
return nil, fmt.Errorf("failed to decode JSON response: %v", err)
}

return &ret, nil
}

func (s *API) GetSubdomain(domain string) (*JsonSubDomain, error) {
Expand Down

0 comments on commit 440e20a

Please sign in to comment.