./c0de/c/finddomains.txt

0.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
/* finddomains.c v1.0 							*/
/* Paul McGinnis, April 22, 1996 					*/
/* [email protected] / 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;
}
 
 

Back