sn0int registry

ellcs/aws-ip-ranges

-- Description: Insert ipv4 and ipv6 ip-ranges published by aws.
-- Version: 0.1.0
-- License: GPL-3.0

function run(pkg)
    local session = http_mksession()
    local req = http_request(session, 'GET', 'https://ip-ranges.amazonaws.com/ip-ranges.json', {})
    local j = http_fetch_json(req)
    local entry

    ipv4_prefixes = j['prefixes']
    for i=1, #ipv4_prefixes do
        entry = ipv4_prefixes[i]
        db_add('netblock', {
            -- family is populated automatically
            -- family=4
            value = entry['ip_prefix'],
            description = "{'service': '" .. entry['service'] .. "', 'region': '" .. entry['region'] .. "', 'network_border_group': '" .. entry['network_border_group'] .. "'}"
        })
    end

    ipv6_prefixes = j['ipv6_prefixes']
    for i=1, #ipv6_prefixes do
        entry = ipv6_prefixes[i]
        db_add('netblock', {
            -- family is populated automatically
            -- family=4
            value = entry['ipv6_prefix'],
            description = "{'service': '" .. entry['service'] .. "', 'region': '" .. entry['region'] .. "', 'network_border_group': '" .. entry['network_border_group'] .. "'}"
        })
    end
end