500 Error using Shodan with PowerShell. Any ideas how to mitigate the issue?

116 Views Asked by At

I'm trying to run the script below to scan open ports from a list of IP Addresses and add the ports to Hudu but I'm encountering a 500 error which will be attached below.

# Setup Hudu
$HuduAPIKey = HuduAPIKey
$BaseUrl = HuduURL
New-HuduAPIKey $HuduAPIKey
New-HuduBaseUrl $BaseUrl

$HuduClients = Get-HuduCompanies
$ShodanAPIKey = ShodanAPIKey

$HuduAssets = Get-HuduAssets | Where-Object Asset_Type -EQ 'WAN/Broadband'
$Field = $HuduIPs.fields | Where-Object Label -EQ "Public IP Address"

foreach ($Asset in $HuduAssets) {
    $Field = $Asset.fields | Where-Object Label -EQ "Public IP Address"
    $IP = $Field.Value
    
    if ($IP -ne $null) {
        $ReqFull = Invoke-RestMethod -uri "https://api.shodan.io/shodan/host/$($ip)?key=$ShodanAPIKey"
        $Ports = $ReqFull.Ports

        if ($Ports -ne $null) {
            Set-HuduAsset -Name "Port Information" -CompanyId $Aseet.company_id -AssetLayoutID $Asset.asset_layout_id -AssetId $Asset.assetid -Fields @(@{'Open Ports' = "$($Ports)" }) 
        }
    }
}

Write-Error: '{"status":500,"error":"Internal Server Error"}'

0

There are 0 best solutions below