How to generate random IPv6 in C#? -
i'm new coding. need know how generate random ipv6 in c sharp. found code generated random ipv4, how can alter ipv6?
static string generateip() { // generate ip in range [50-220].[10-100].[1-255].[1-255] return rng.next(50, 220).tostring() + "." + rng.next(10, 100).tostring() + "." + rng.next(1, 255).tostring() + "." + rng.next(1, 255).tostring(); } } class rng { private static random _rng = new random(); public static int next(int min, int max) { return _rng.next(min, max); }
what constraints around generated address? if none, it's pretty simple. should work:
byte[] bytes = new byte[16]; new random().nextbytes(bytes); ipaddress ipv6address = new ipaddress(bytes); string addressstring = ipv6address.tostring();
Comments
Post a Comment