User Controls

I don't even know what the fuck I am doing anymore

  1. #1
    filtration Tuskegee Airman

    #################################
    # Generate IP and save to file
    #################################
    function generateIP() {

    # Initiate parts
    PART1=$1
    PART2=$2
    PART3=$3
    PART4=$4

    # Set up ranges
    if [ "$PART1" -eq 255 ]; then
    PART1RANGE={0.255};
    else
    PART1RANGE={$PART1..255}
    fi

    if [ "$PART2" -eq 255 ]; then
    PART2RANGE={0.255};
    else
    PART2RANGE={$PART2..255}
    fi

    if [ "$PART3" -eq 255 ]; then
    PART3RANGE={0.255};
    else
    PART3RANGE={$PART3..255}
    fi

    if [ "$PART4" -eq 255 ]; then
    PART4RANGE={0.255};
    else
    PART4RANGE={$PART4..255}
    fi

    for first in $PART1RANGE; do
    for second in $PART2RANGE; do
    for third in $PART3RANGE; do
    for fourth in $PART4RANGE; do
    echo "wtf"
    echo "$first.$second.$third.$fourth"
    # Save ips to file for scanning
    #echo "$part1.$part2.$part3.$part4" >> "$OUTPUTFOLDER/$OUTPUT"
    done
    done
    done
    done
    }


  2. #2
    filtration Tuskegee Airman
    Ahhh yes, much better


    #################################
    # Generate IP and save to file
    #################################
    function generateIP() {

    # Initiate parts
    PART1=$1
    PART2=$2
    PART3=$3
    PART4=$4

    if [ "$PART1" -eq 255 ]; then PART1=0; else PART1=$PART1; fi
    for first in $(eval echo {$PART1..255}); do

    if [ "$PART2" -eq 255 ]; then PART2=0; else PART2=$PART2; fi
    for second in $(eval echo {$PART2..255}); do

    if [ "$PART3" -eq 255 ]; then PART3=0; else PART3=$PART3; fi
    for third in $(eval echo {$PART3..255}); do

    if [ "$PART4" -eq 255 ]; then PART4=0; else PART4=$PART4; fi
    for fourth in $(eval echo {$PART4..255}); do
    echo "$first.$second.$third.$fourth"
    # Save ips to file for scanning
    #echo "$part1.$part2.$part3.$part4" >> "$OUTPUTFOLDER/$OUTPUT"
    done
    done
    done
    done
    }
  3. #3
    filtration Tuskegee Airman
    Actually it's not, it doesn't rest back to 0... FML
  4. #4
    aldra JIDF Controlled Opposition
    why

    0.0.0.0/0 oll
  5. #5
    filtration Tuskegee Airman
    Originally posted by aldra why

    0.0.0.0/0 oll

    What do you mean?
  6. #6
    aldra JIDF Controlled Opposition
    why are you making a list of all possible ipv4 addresses

    you could use subnet notation to pass a range anywhere you might need to
  7. #7
    filtration Tuskegee Airman
    Originally posted by aldra why are you making a list of all possible ipv4 addresses

    you could use subnet notation to pass a range anywhere you might need to

    A script I'm using requires actual IP's/Domains.
  8. #8
    aldra JIDF Controlled Opposition

    for(a=0;a<255;a++)
    {
    for(b=0;b<255;b++)
    {
    for(c=0;c<255;c++)
    {
    for(d=0;d<255;d++)
    {
    address="$a.$b.$c.$d";
    print(address);

    }
    }
    }
    }


    or something
    The following users say it would be alright if the author of this post didn't die in a fire!
  9. #9
    filtration Tuskegee Airman
    Originally posted by aldra

    for(a=0;a<255;a++)
    {
    for(b=0;b<255;b++)
    {
    for(c=0;c<255;c++)
    {
    for(d=0;d<255;d++)
    {
    address="$a.$b.$c.$d";
    print(address);

    }
    }
    }
    }


    or something

    That's what I am doing above :D
  10. #10
    filtration Tuskegee Airman
    If you're wondering why I am trying to reset and what not, here's the rest of the code I wrote so you know what I am trying to achieve...


    OUTPUTFOLDER="../../scan/toscan/generated"
    LASTGENERATEDFILE=$(ls -t $OUTPUTFOLDER | head -1)
    OUTPUT="1.txt"

    #################################
    # Check the last generated file
    #################################
    function lastGeneratedFile() {
    if [ -z $LASTGENERATEDFILE ]; then
    OUTPUT="1.txt"
    fi
    }

    #################################
    # Check the last generated IP
    #################################
    function lastGeneratedIP() {
    echo $(cat $OUTPUTFOLDER/$LASTGENERATEDFILE | tail -1)
    }

    #################################
    # Limit lines to 65,000 ips
    # @todo use memory, rather than this
    #################################
    function hasMaxiumLines() {
    if [ $(wc -l $OUTPUTFOLDER/$LASTGENERATEDFILE | awk '{print $1}') -lt 65000 ]; then
    OUTPUT=$LASTGENERATEDFILE;
    fi
    }

    #################################
    # Incrememnts file name by 1
    #################################
    function incrementFileName() {
    id=$(basename $LASTGENERATEDFILE .txt)
    OUTPUT="$((id + 1)).txt"
    }


    #################################
    # Generate IP and save to file
    #################################
    function generateIP() {

    # Initiate parts
    PART1=$1
    PART2=$2
    PART3=$3
    PART4=$4

    if [ "$PART1" -eq 255 ]; then PART1=0; else PART1=$PART1; fi
    for first in $(eval echo {$PART1..255}); do

    if [ "$PART2" -eq 255 ]; then PART2=0; else PART2=$PART2; fi
    for second in $(eval echo {$PART2..255}); do

    if [ "$PART3" -eq 255 ]; then echo "reset"; PART3=0; else PART3=$PART3; fi
    for third in $(eval echo {$PART3..255}); do

    if [ "$PART4" -eq 255 ]; then PART4=0; else PART4=$PART4; fi
    for fourth in $(eval echo {$PART4..255}); do
    echo $PART4
    # Add to memory
    #echo "$first.$second.$third.$fourth"
    done
    done

    # Write store ips from memoroy to file
    #echo "$part1.$part2.$part3.$part4" >> "$OUTPUTFOLDER/$OUTPUT"
    done
    done
    }

    #################################
    # Start generating the IP's
    #################################
    function main() {
    # get the last generated IP
    lastIP=`lastGeneratedIP`
    IFS='.' read -r -a array <<< "$lastIP"

    # check last IP, start from index
    if [ -n $lastIP ]; then
    generateIP "${array[0]}" "${array[1]}" "${array[2]}" "${array[3]}"
    else
    generateIP "0" "0" "0" "0"
    fi
    }

    main
  11. #11
    filtration Tuskegee Airman
    Jesus christ, don't program when tired, you over think things...


    #################################
    # Generate IP and save to file
    #################################
    function generateIP() {

    # Initiate parts
    PART1=$1
    PART2=$2
    PART3=$3
    PART4=$4

    for first in $(eval echo {$PART1..255}); do
    for second in $(eval echo {$PART2..255}); do
    for third in $(eval echo {$PART3..255}); do
    for fourth in $(eval echo {$PART4..255}); do
    echo "$first.$second.$third.$fourth"
    done
    # Reset variable
    PART4=0
    done
    # Reset variable
    PART3=0
    # Write store ips from memoroy to file
    #echo "$part1.$part2.$part3.$part4" >> "$OUTPUTFOLDER/$OUTPUT"
    done
    # Reset variable
    PART2=0
    done
    }

  12. #12
    filtration Tuskegee Airman
    500,000 ips a minute, meh. My next step is the speed it up.
  13. #13
    Lanny creature of the mesothelioma era
    semi-oneliner for fun:

    n="0"; while [ $n -lt $((1 << 32)) ]; do; echo "$(((n & 0XFF000000) >> 24)).$(((n & 0XFF0000) >> 16)).$(((n & 0XFF00) >> 8)).$((n & 0XFF))"; n=$[$n + 1]; done
  14. #14
    Lanny creature of the mesothelioma era
    This was the fastest I managed to get:


    #define buflines 2048

    int main() {
    char *lu = malloc(3*256+1);
    for (int k=0; k<256; k++) {
    sprintf(lu+(k*3), "%03d", k);
    }
    lu[3*256+1] = '\0';

    char *buf = malloc(buflines * 16 + 1);
    for (int k = 0; k < buflines; k++) {
    buf[k*16 + 3] = '.';
    buf[k*16 + 7] = '.';
    buf[k*16 + 11] = '.';
    buf[k*16 + 15] = '\n';
    }

    int p;
    char *bufp;
    unsigned int i = 1 << 24;
    while (i) {
    bufp = buf;
    for (int k = 0; k < buflines; k++) {
    p = ((i & 0xff000000) >> 24) * 3;
    bufp[0] = *(lu+p);
    bufp[1] = *(lu+p+1);
    bufp[2] = *(lu+p+2);

    p = ((i & 0xff0000) >> 16) * 3;
    bufp[4] = *(lu+p);
    bufp[5] = *(lu+p+1);
    bufp[6] = *(lu+p+2);

    p = ((i & 0xff00) >> 8) * 3;
    bufp[8] = *(lu+p);
    bufp[9] = *(lu+p+1);
    bufp[10] = *(lu+p+2);

    p = (i & 0xff) * 3;
    bufp[12] = *(lu+p);
    bufp[13] = *(lu+p+1);
    bufp[14] = *(lu+p+2);

    bufp += 16;
    i--;
    }

    //printf("%s", buf);
    write(1, buf, buflines * 16);
    }
    return 0;
    }



    [lanny:~/killme]$ time ./a.out > /dev/null
    ./a.out > /dev/null 0.07s user 0.00s system 97% cpu 0.081 total


    16 million lines in ~0.5 seconds cold, ~0.08 on the second run. Interestingly `printf("%s", buf)` outperforms a direct write which surprised me, but I'm guessing printf has some buffering going on because when I added the internal buffer it got a lot faster.
    The following users say it would be alright if the author of this post didn't die in a fire!
  15. #15
    aldra JIDF Controlled Opposition
    lol I was just going to say don't perform the write for each line

    is the original code sh? I can't tell
  16. #16
    Lanny creature of the mesothelioma era
    Yee, or zsh, but I think it's all bash-compatible. No idea about classic borne.
Jump to Top