none
Generate random ip addresss RRS feed

Answers

  • Hi Ardmore,

    an IP normally looks like this: 192.168.178.200.

    So a random generator for 10 ips could be implemented like below:

        class Program
        {
            static void Main(string[] args)
            {
                var ips = new List<string>();
                for (int i = 0; i < 10; i++)
                {
                    ips.Add(RandomIpGenerator.GetRandomIp());
                }
    
                foreach (var ip in ips)
                {
                    Console.WriteLine(ip);
                }
    
                Console.ReadLine();
            }
    
    
        }
    
        public static class RandomIpGenerator
        {
            private static Random _random = new Random();
            public static string GetRandomIp()
            {
                return string.Format("{0}.{1}.{2}.{3}", _random.Next(0, 255), _random.Next(0, 255), _random.Next(0, 255), _random.Next(0, 255));
            }
        }


    Thomas Claudius Huber

    "If you can't make your app run faster, make it at least look & feel extremly fast"

    My latest Pluralsight-course: Windows Store Apps - Data Binding in Depth

    twitter: @thomasclaudiush
    homepage: www.thomasclaudiushuber.com
    author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook

    • Marked as answer by ardmore Monday, August 4, 2014 6:49 PM
    Monday, August 4, 2014 6:46 PM

All replies

  • Hi Ardmore,

    an IP normally looks like this: 192.168.178.200.

    So a random generator for 10 ips could be implemented like below:

        class Program
        {
            static void Main(string[] args)
            {
                var ips = new List<string>();
                for (int i = 0; i < 10; i++)
                {
                    ips.Add(RandomIpGenerator.GetRandomIp());
                }
    
                foreach (var ip in ips)
                {
                    Console.WriteLine(ip);
                }
    
                Console.ReadLine();
            }
    
    
        }
    
        public static class RandomIpGenerator
        {
            private static Random _random = new Random();
            public static string GetRandomIp()
            {
                return string.Format("{0}.{1}.{2}.{3}", _random.Next(0, 255), _random.Next(0, 255), _random.Next(0, 255), _random.Next(0, 255));
            }
        }


    Thomas Claudius Huber

    "If you can't make your app run faster, make it at least look & feel extremly fast"

    My latest Pluralsight-course: Windows Store Apps - Data Binding in Depth

    twitter: @thomasclaudiush
    homepage: www.thomasclaudiushuber.com
    author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook

    • Marked as answer by ardmore Monday, August 4, 2014 6:49 PM
    Monday, August 4, 2014 6:46 PM
  • Generating random IP addresses has evolved with technological advancements since 2014. Today, one popular method is using programming languages or libraries that offer built-in functionalities for randomization. For example, in Python, you can utilize the ipaddress module along with a random number generator to generate random IP addresses. This approach ensures the validity of the generated addresses within the IPv4 address space.

    Alternatively, for a convenient and reliable solution, you can utilize online tools like https://randomtools.io/random-ipaddress-generator/. This website offers a dedicated random IP address generator that generates valid and up-to-date IP addresses. Simply specify the number of addresses you need, and the tool will provide you with the random IP addresses, eliminating the need for manual coding.

    By leveraging programming languages with built-in randomization features or using dedicated online tools like random IP address generator, you can easily generate random IP addresses in a more efficient and accurate manner in 2023. These modern solutions offer improved convenience and reliability compared to the methods available back in 2014.
    Saturday, May 20, 2023 10:57 AM