#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef char str64 [64];
typedef unsigned long ulong;

void main (ulong arg_c, char *arg_v[])
{
  if (arg_c != 2 || !strstr (arg_v[1], ".")) exit (-1);

  for (ulong cntr = 1; cntr <= 255; cntr ++) 
  {
    str64 host, addr = "";

    sprintf (host, "%d", cntr);
    strcpy (addr, arg_v[1]); 
    strcat (addr, "."); 
    strcat (addr, host);

    long child = fork ();

    if (child != -1)                                                           /* fork() succeeded */
    {
      if (child == 0)                                                          /* fork() returns 0 to the child process */
      {
        str64 task = "";

        strcpy (task, "ping -c 1 -t 1 ");
        strcat (task, addr);
        strcat (task, " 2>/dev/null");
        strcat (task, " | grep icmp");

        system (task);

        exit (0);
      }
      else                                                                     /* fork() returns new pid to the parent process */
      {
        ;
      }
    } 
    else                                                                       /* fork() returns -1 on failure */
    {
      exit (-1);
    }
  }

  while (wait (NULL) > 0) {}

  exit (0);
}