Skip to content

Commit

Permalink
Update api.go
Browse files Browse the repository at this point in the history
  • Loading branch information
incogbyte authored Oct 5, 2024
1 parent b89a1c0 commit 9cf4320
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions apishodan/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,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 {
fmt.Println(">> Something went wrong")
panic(err)
}

defer res.Body.Close()

var ret JsonData

if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, 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 9cf4320

Please sign in to comment.