Visit our newest sister site!
Hundreds of free aircraft flight manuals
Civilian • Historical • Military • Declassified • FREE!


TUCoPS :: Hacking Techniques :: findoms.c

findomains.c findomains.c is a simple program to find the names associated with a class C worth of IP's.




/* finddomains.c v1.0 */
/* Paul McGinnis, April 22, 1996 */
/* TRADER@cup.portal.com / http://www.portal.com/~trader/secrecy.html */
/* program finds up to 255 hosts on a specified domain */
/* must be linked with socket and nsl libraries on Sun */
/* to compile, use:  cc -ofinddomains finddomains.c -lsocket -lnsl */

#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>

u_long ip_to_ulong(char *);

/* function converts an ASCII string into a 32-bit unsigned long IP address */
u_long ip_to_ulong(char *ip_string)
{
  u_long x;
  int i;
  char tmp_str[4] = "\0\0\0\0";
  x = 0;
  for (i = 0; i < 20; ++i)
  {
    if (isdigit(ip_string[i]))
      strncat(tmp_str, &ip_string[i], 1);
    else if ((ip_string[i] == '.') || (ip_string[i] == '\0'))
    {
      strcat(tmp_str, "\0");
      x = x << 8;
      x += (u_long) atol(tmp_str);
      strncpy(tmp_str, "\0\0\0\0", 4);
      if (ip_string[i] == '\0')
        break;
    }
  }
  return x;
}


int main(int argc, char **argv)
{
  char IP_address[20];
  u_long u_addr;
  int i;
  unsigned char j;
  struct hostent *hostent_buffer;
  puts("finddomains v1.0-finds hosts on a domain");
  if (argc !=2)
  {
    printf("Enter IP address of a host on the target domain: ");
    gets(IP_address);
  }
  else
    strcpy(IP_address, argv[1]);
  u_addr = ip_to_ulong(IP_address);
  j = 0;
  for (i = 0; i < 20; ++i)
  {
    if (IP_address[i] == '.')
      j++;
    if (j == 3)
    {
      IP_address[i] = '\0';
      break;
    }
  }
  for (j = 0; j < 255; ++j)
  {
    u_addr = (u_addr & 0xffffff00) + j;
    hostent_buffer = gethostbyaddr((char *)&u_addr, sizeof(u_addr), AF_INET);
    /* use AF_INET constant to indicate IP address type */
    if (hostent_buffer == NULL)
      continue;
    else
      printf("%s.%d = %s\n", IP_address, j, hostent_buffer->h_name);
  }
  return 0;
}



TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2014 AOH