Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Need ipv6 address generator
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Need ipv6 address generator

RurikoRuriko Member

Is there a online tool or software where i can input subnet and get hundreds of random addresses from ipv6 subnet? google ain't helping me as it just gives me ipv6 calculators

Comments

  • NeoonNeoon Community Contributor, Veteran
  • MikeAMikeA Member, Patron Provider
    edited March 25

    ChatGPT can do that in a second.

    Thanked by 1host_c
  • tentortentor Member, Patron Provider
    edited March 25
    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    #include <string.h>
    #include <arpa/inet.h>
    #include <sys/param.h>
    
    int main(int argc, char** argv) {
      srand(time(NULL));
    
      if (argc == 4) {
        int mask = atoi(argv[3]);
    
        if (strcmp(argv[1], "-4") == 0) {
          if (mask > 32) {
            printf("invalid mask given\n");
        return 1;
          }
    
          struct in_addr addr;
          if (inet_pton(AF_INET, argv[2], (void*)&addr.s_addr) == 0) {
            printf("invalid address given\n");
            return 1;
          }
    
          // addr.s_addr = addr.s_addr & ((1 << (mask + 1)) - 1);
    
          addr.s_addr = addr.s_addr & ntohl((1 << (mask + 1)) - 1);
          int r = rand() >> mask;
          addr.s_addr = addr.s_addr | ntohl(r);
    
          printf("%d\n", htonl((int)addr.s_addr));
        }
    
        if (strcmp(argv[1], "-6") == 0) {
          if (mask > 128) {
            printf("invalid mask given\n");
        return 1;
          }
    
          mask = 128 - mask;
    
          struct in6_addr addr;
          if (inet_pton(AF_INET6, argv[2], (void*)&addr) == 0) {
            printf("invalid address given\n");
            return 1;
          }
    
          for (char i = 15; mask > 0; i--) {
            unsigned char m = (char)((1 << MIN(8, mask)) - 1);
            unsigned char r = (unsigned char)rand() & m/*0*/;
            addr.s6_addr[i] = addr.s6_addr[i] & (~m) | r;
            mask -= 8;
          }
    
          for (char i = 0; i < 16; i += 2) {
            printf("%x", (addr.s6_addr[i] << 8) +  addr.s6_addr[i + 1]);
    
        if (i != 14)
              printf(":");
          }
        }
    
        printf("\n");
    
        return 0;
      }
    
      return 1;
    }
    

    Then

    gcc -o main{,.c}
    ./main -6 2a09:b280:fe00:: 48
    

    Arguments used here are:

    • -6 required for IPv6
    • 2a09:b280:fe00:: the address of your IPv6 prefix
    • 48 the prefix length (i.e. 2a09:b280:fe00::/48)

    Run it as many times as you need to.

  • yoursunnyyoursunny Member, IPv6 Advocate

    I often generate a random hexadecimal sequence with openssl rand -hex 8 and manually insert colons.

  • @Ruriko said:
    Is there a online tool or software where i can input subnet and get hundreds of random addresses from ipv6 subnet? google ain't helping me as it just gives me ipv6 calculators

    Yes, you can use online tools like the IPv6 Random Address Generator to input a subnet and generate hundreds of random IPv6 addresses from that subnet.

  • kevindskevinds Member, LIR
    edited March 28

    @Ruriko said:
    Is there a online tool or software where i can input subnet and get hundreds of random addresses from ipv6 subnet?

    You are putting too much effort into this..

    Generate random hex digits, put them at the end of your prefix, that is it.

  • raindog308raindog308 Administrator, Veteran

    @yoursunny said: I often generate a random hexadecimal sequence with openssl rand -hex 8 and manually insert colons.

    @kevinds said: Generate random hex digits, put them at the end of your prefix, that is it.

    These solutions are not going to collapse zeroes as is the norm in IPv6 addresses, though OP may not need that.

  • @yoursunny Has ipv9 generator ?

    Thanked by 1yoursunny
  • kevindskevinds Member, LIR

    @raindog308 said:
    These solutions are not going to collapse zeroes as is the norm in IPv6 addresses, though OP may not need that.

    Randomly generated addresses won't have that many 0s for that to matter.

  • RurikoRuriko Member

    @kevinds said:

    @Ruriko said:
    Is there a online tool or software where i can input subnet and get hundreds of random addresses from ipv6 subnet?

    You are putting too much effort into this..

    Generate random hex digits, put them at the end of your prefix, that is it.

    But I want to generate a list of 1000 ipv6 random address. Doing it manual is too time consuming

  • kevindskevinds Member, LIR

    @Ruriko said:
    But I want to generate a list of 1000 ipv6 random address. Doing it manual is too time consuming

    Hardest part is only getting hex characters randomly.

    Second hardest is choosing how you want the output..

  • edited March 30

    https://ip6.sh is a good one. You can generate as many as you want.

  • totototototo Member

    @Ruriko said:
    But I want to generate a list of 1000 ipv6 random address. Doing it manual is too time consuming

    prefix="2001:0db8:"
    declare -a addresses
    while [ ${#addresses[@]} -lt 1000 ]
    do
        random_data=$(od -A n -t x1 -N 16 /dev/urandom | tr -d ' \n')
        ipv6_address="${prefix}"
        for ((j=0; j<16; j+=4))
        do
            ipv6_address+=":${random_data:$j:4}"
        done
        duplicate=0
        for addr in "${addresses[@]}"
        do
            if [ "$addr" == "$ipv6_address" ]; then
                duplicate=1
                break
            fi
        done
        if [ $duplicate -eq 0 ]; then
            addresses+=("$ipv6_address")
        fi
    done
    IFS=$'\n' sorted=($(sort <<<"${addresses[*]}"))
    for addr in "${sorted[@]}"
    do
        echo "$addr"
    done
    

    by ChatGPT

  • Plot twist: he uses someone else's prefix and doesn't work.

    Or you can just turn on privacy and temporary addresses.

Sign In or Register to comment.