Skip to content

Instantly share code, notes, and snippets.

@mika
Forked from azet/get_alexa_1m_mx_rrs
Created September 6, 2017 08:55
Show Gist options
  • Save mika/6cb71e1cb67fa69a8c6a0be5285bd91b to your computer and use it in GitHub Desktop.
Save mika/6cb71e1cb67fa69a8c6a0be5285bd91b to your computer and use it in GitHub Desktop.

Revisions

  1. @azet azet revised this gist Jul 31, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,9 @@ function get_mx() {
    unzip "${top1m_zip}" &> /dev/null
    }

    [[ ${1} == "get_mx" ]] && { get_mx "${2}" && exit 0 }
    [[ ${1} == "get_mx" ]] && {
    get_mx "${2}" && exit 0
    }

    if [[ $(which parallel) ]]; then
    printf "<< parallel mode >>\n\n" >&2
  2. @azet azet revised this gist Jul 31, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -42,9 +42,7 @@ function get_mx() {
    unzip "${top1m_zip}" &> /dev/null
    }

    [[ ${1} == "get_mx" ]] && {
    get_mx "${2}" && exit 0
    }
    [[ ${1} == "get_mx" ]] && { get_mx "${2}" && exit 0 }

    if [[ $(which parallel) ]]; then
    printf "<< parallel mode >>\n\n" >&2
  3. @azet azet revised this gist Jul 31, 2015. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -43,8 +43,7 @@ function get_mx() {
    }

    [[ ${1} == "get_mx" ]] && {
    get_mx "${2}" || exit 1
    exit 0
    get_mx "${2}" && exit 0
    }

    if [[ $(which parallel) ]]; then
  4. @azet azet revised this gist Jul 31, 2015. No changes.
  5. @azet azet revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,7 @@ if [[ $(which parallel) ]]; then
    printf "<< parallel mode >>\n\n" >&2
    parallel --progress --colsep ',' "${0} get_mx {2}" :::: ${top1m_csv}
    else
    printf "<< sequential mode (slow! install \`parallel\` for speed.) >>\n\n" >&2
    printf "<< sequential mode (slow! install \`parallel\`.) >>\n\n" >&2
    for host in $(hosts); do
    get_mx "${host}"
    done
  6. @azet azet revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,7 @@ if [[ $(which parallel) ]]; then
    printf "<< parallel mode >>\n\n" >&2
    parallel --progress --colsep ',' "${0} get_mx {2}" :::: ${top1m_csv}
    else
    printf "<< sequential mode (fuck-slow!) >>\n\n" >&2
    printf "<< sequential mode (slow! install \`parallel\` for speed.) >>\n\n" >&2
    for host in $(hosts); do
    get_mx "${host}"
    done
  7. @azet azet revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ function get_mx() {
    +time=2 mx "${1}" | sed 's/.*\ //'))
    printf '{\n\t"%s": {\n\t\t"mx_records": [\n' "${1}"
    for mx in "${mx_records[@]}"; do
    local ip=($(getent ahostsv4 ${mx})) # we only need v4 for scanning
    local ip=($(getent ahostsv4 ${mx})) # in our case, v4 suffices.
    printf '\t\t\t"%s": \t"%s",\n' "${mx}" "${ip}"
    done
    printf "\t\t]\n\t}\n}\n"
  8. @azet azet revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@
    # Authors: Aaron Zauner <[email protected]>
    # License: CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0)
    #
    set -e pipefail
    set -eo pipefail

    readonly top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    readonly top1m_zip=${top1m_s3l##*/}
  9. @azet azet revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@
    # Authors: Aaron Zauner <[email protected]>
    # License: CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0)
    #
    set -e
    set -e pipefail

    readonly top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    readonly top1m_zip=${top1m_s3l##*/}
  10. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -58,4 +58,4 @@ else
    fi
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<< finished run. >> \
    $(date --rfc-3339=ns).\n" >&2 }' EXIT
    $(date --rfc-3339=ns) \n" >&2 }' EXIT
  11. @azet azet revised this gist Jul 30, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -56,5 +56,6 @@ else
    get_mx "${host}"
    done
    fi
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<< finished. >>\n" >&2 }' EXIT
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<< finished run. >> \
    $(date --rfc-3339=ns).\n" >&2 }' EXIT
  12. @azet azet revised this gist Jul 30, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,8 @@
    #
    # Retrieves MX and A records for 'Alexa Top 1 Million' hosts
    # and prints them as pretty formatted JSON objects to stdout.
    # Optional parallelism support with GNU Parallel (recommended):
    #
    # *Optional* parallelism support with GNU Parallel (recommended):
    # $ sudo apt-get install parallel
    #
    # Authors: Aaron Zauner <[email protected]>
  13. @azet azet revised this gist Jul 30, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env bash
    #
    # Retrieves MX and A records for 'Alexa Top 1 Million' list
    # and prints them as nicely formatted JSON object to stdout.
    # Retrieves MX and A records for 'Alexa Top 1 Million' hosts
    # and prints them as pretty formatted JSON objects to stdout.
    # Optional parallelism support with GNU Parallel (recommended):
    # $ sudo apt-get install parallel
    #
  14. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # Retrieves MX and A records for 'Alexa Top 1 Million' list
    # and prints them as nicely formatted JSON object to stdout.
    # Optional parallelism support with GNU Parallel (recommended):
    # `sudo apt-get install parallel`
    # $ sudo apt-get install parallel
    #
    # Authors: Aaron Zauner <[email protected]>
    # License: CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0)
  15. @azet azet revised this gist Jul 30, 2015. No changes.
  16. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    #
    # Retrieves MX and A records for 'Alexa Top 1 Million' list
    # and prints them as nicely formatted JSON object to stdout.
    # Optionally supports GNU Parallel (recommended):
    # Optional parallelism support with GNU Parallel (recommended):
    # `sudo apt-get install parallel`
    #
    # Authors: Aaron Zauner <[email protected]>
  17. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ function get_mx() {
    +time=2 mx "${1}" | sed 's/.*\ //'))
    printf '{\n\t"%s": {\n\t\t"mx_records": [\n' "${1}"
    for mx in "${mx_records[@]}"; do
    local ip=($(getent ahostsv4 ${mx})) # only need v4 for scanning
    local ip=($(getent ahostsv4 ${mx})) # we only need v4 for scanning
    printf '\t\t\t"%s": \t"%s",\n' "${mx}" "${ip}"
    done
    printf "\t\t]\n\t}\n}\n"
  18. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ function get_mx() {
    +time=2 mx "${1}" | sed 's/.*\ //'))
    printf '{\n\t"%s": {\n\t\t"mx_records": [\n' "${1}"
    for mx in "${mx_records[@]}"; do
    local ip=($(getent ahostsv4 ${mx}))
    local ip=($(getent ahostsv4 ${mx})) # only need v4 for scanning
    printf '\t\t\t"%s": \t"%s",\n' "${mx}" "${ip}"
    done
    printf "\t\t]\n\t}\n}\n"
  19. @azet azet revised this gist Jul 30, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -10,9 +10,9 @@
    #
    set -e

    top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    top1m_zip=${top1m_s3l##*/}
    top1m_csv=${top1m_zip%.*}
    readonly top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    readonly top1m_zip=${top1m_s3l##*/}
    readonly top1m_csv=${top1m_zip%.*}

    function hosts() {
    for line in $(<${top1m_csv}); do
  20. @azet azet revised this gist Jul 30, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -55,5 +55,5 @@ else
    get_mx "${host}"
    done
    fi
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<<finished.>>\n" >&2 }' EXIT
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<< finished. >>\n" >&2 }' EXIT
  21. @azet azet revised this gist Jul 30, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,6 @@ set -e
    top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    top1m_zip=${top1m_s3l##*/}
    top1m_csv=${top1m_zip%.*}
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<<finished.>>\n" >&2 }' EXIT

    function hosts() {
    for line in $(<${top1m_csv}); do
    @@ -56,4 +54,6 @@ else
    for host in $(hosts); do
    get_mx "${host}"
    done
    fi
    fi
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<<finished.>>\n" >&2 }' EXIT
  22. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    top1m_zip=${top1m_s3l##*/}
    top1m_csv=${top1m_zip%.*}
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<<finished.>>\n" >&2}' EXIT
    printf "\n\n<<finished.>>\n" >&2 }' EXIT

    function hosts() {
    for line in $(<${top1m_csv}); do
  23. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ set -e
    top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    top1m_zip=${top1m_s3l##*/}
    top1m_csv=${top1m_zip%.*}
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<<finished.>>\n" >&2}' EXIT

    function hosts() {
  24. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ set -e
    top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    top1m_zip=${top1m_s3l##*/}
    top1m_csv=${top1m_zip%.*}
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<<finished.>>\n" >&2}' EXIT

    function hosts() {
  25. @azet azet revised this gist Jul 30, 2015. No changes.
  26. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ set -e
    top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    top1m_zip=${top1m_s3l##*/}
    top1m_csv=${top1m_zip%.*}
    trap '{ rm ${top1m_zip} ${top1m_csv} ; \
    trap '{ rm ${top1m_zip} ${top1m_csv}; \
    printf "\n\n<<finished.>>\n" >&2}' EXIT

    function hosts() {
  27. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ set -e
    top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    top1m_zip=${top1m_s3l##*/}
    top1m_csv=${top1m_zip%.*}
    trap '{ rm ${top1m_zip} ${top1m_csv} ; \
    trap '{ rm ${top1m_zip} ${top1m_csv} ; \
    printf "\n\n<<finished.>>\n" >&2}' EXIT

    function hosts() {
  28. @azet azet revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ set -e
    top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    top1m_zip=${top1m_s3l##*/}
    top1m_csv=${top1m_zip%.*}
    trap '{ rm ${top1m_zip} ${top1m_csv} ;\
    trap '{ rm ${top1m_zip} ${top1m_csv} ; \
    printf "\n\n<<finished.>>\n" >&2}' EXIT

    function hosts() {
  29. @azet azet revised this gist Jul 30, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,8 @@ set -e
    top1m_s3l="https://s3.amazonaws.com/alexa-static/top-1m.csv.zip"
    top1m_zip=${top1m_s3l##*/}
    top1m_csv=${top1m_zip%.*}
    trap '{rm ${top1m_zip} ${top1m_csv} ; printf "\n\n<<finished.>>\n" >&2}' EXIT
    trap '{ rm ${top1m_zip} ${top1m_csv} ;\
    printf "\n\n<<finished.>>\n" >&2}' EXIT

    function hosts() {
    for line in $(<${top1m_csv}); do
  30. @azet azet revised this gist Jul 30, 2015. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions get_alexa_1m_mx_rrs
    Original file line number Diff line number Diff line change
    @@ -50,8 +50,6 @@ function get_mx() {
    if [[ $(which parallel) ]]; then
    printf "<< parallel mode >>\n\n" >&2
    parallel --progress --colsep ',' "${0} get_mx {2}" :::: ${top1m_csv}
    trap INT HUP '{ echo "singal! exiting early, keeping files" ; exit 1 }'
    rm ${top1m_zip} ${top1m_csv}
    else
    printf "<< sequential mode (fuck-slow!) >>\n\n" >&2
    for host in $(hosts); do