# shellcheck shell=bash disable=SC2154,SC2034
___x_cmd_shodan_scan_port(){
    local X_help_cmd='x help -m shodan scan port';  help:arg:parse
    shodan:arg:format:raw:json2app:all
    shodan:info "List all ports that Shodan is crawling on the Internet"
    ___x_cmd_shodan_scan_port___"$format"
}

___x_cmd_shodan_scan_port___app(){
    local data; data="$( ___x_cmd_shodan_scan_port___json )" || shodan:data:ret
    ___x_cmd_pipevar    data    ___x_cmd_shodan_scan_port___parse_json2pick
}

___x_cmd_shodan_scan_port___json(){
    local data; data="$( ___x_cmd_shodan_scan_port___raw )" || {
        shodan:error "Fail to get scan port data"
        shodan:data:ret
    }

    ___x_cmd_pipevar    data
}

___x_cmd_shodan_scan_port___raw(){
    X_CCMD_TIMEOUT=10m ___x_cmd_shodan_ourl get "/shodan/ports"
}

# Sectin: parse
___x_cmd_shodan_scan_port___parse_json2pick(){
    x ja 'END{ l = O[S "\"1\"" L]; for(i=1; i<l; i++) print O[S "\"1\"" S "\""i"\""] }' |\
        x pick --col 10
}
# EndSection
