Ping done easy (by yourself – coders only)

I just connected a headless Raspberry Pi to a wifi adapter but I did not know which IP Address was given. I need that address to make contact with PuTTY.

So I wanted to figure out the IP Address. As a programmer, what should I do? Surf the internet for some nifty tool? Of should I write some code? I have chosen the latter.

So now I ping each port with:

internal class Program
{
    private static void Main(string[] args)
    {
        for (int i = 90; i < 254; i++)
        {
            Console.Write("192.168.0." + i + ": ");
            Console.WriteLine(Ping("192.168.0." + i));
        }
    }
 
    public static bool Ping(string nameOrAddress)
    {
        Ping ping = new Ping();
        try
        {
            var response = ping.Send(nameOrAddress);
            var pinged = (response.Status == IPStatus.Success);
 
            return pinged;
        }
        catch (PingException)
        {
            return false;
        }
    }
}

So start it and take a cup of coffee…

And check the addresses:

ping01

This is simple to use, have fun with it!

 

Advertenties