forked from ricardolongatto/dnsrato
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdnsrato.c
81 lines (66 loc) · 2.01 KB
/
dnsrato.c
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
#include "dnsrato.h"
void splash(void) {
printf("|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|\n");
printf("|-|-|-|-|-|-|-|-|-|-|-|.. DNSRATO v1.0 .. |-|-|-|-|-|-|-|-|-|-|-|-|-|\n");
printf("|-|-|-|-|-|-|-|-| Uso: ./dnsrato alvo.com.br rato.txt |-|-|-|-|-|-|-|\n");
printf("|-|-|-|-|-| Ricardo Longatto -- [email protected] |-|-|-|-|-|\n");
printf("|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|\n");
}
int file_possible_len(FILE * fp) {
char c;
int lines = 0;
while (!feof(fp)) {
c = fgetc(fp);
if (c == 0x0a) {
lines++;
}
}
rewind(fp);
return ++lines;
}
void
nslookup (const int argc, char ** argv, dnsdata_v * dnsV) {
char * result;
FILE * rato;
char txt[50];
struct hostent * host;
BOOL matched = FALSE;
size_t i = 0;
rato = ( (argc < 3) ? fopen (DEFAULT_WORLDLIST, "r") : fopen (argv[2], "r") );
if (rato == NULL) {
fprintf (stderr, "[ERROR] - Opening the file: %s\n",
( (argc < 3) ? DEFAULT_WORLDLIST : argv[2]) );
exit (1);
}
dnsV->dnsData = (dnsdata_t *) calloc(file_possible_len (rato), sizeof(dnsdata_t) );
while(fscanf(rato, "%s", &txt) != EOF) {
result = (char *) strcat (txt,argv[1]);
host=gethostbyname (result);
if (host == NULL) {
continue;
} else {
strncpy (dnsV->dnsData[i].host, result, HOSTLEN);
dnsV->dnsData[i].host_addr = inet_ntoa ( *( (struct in_addr *)(host)->h_addr));
matched = TRUE;
i++;
}
}
if (matched == FALSE) {
free (dnsV->dnsData);
dnsV->dnsData = NULL;
}
dnsV->size = i;
}
void
nslookup_dump (dnsdata_v * dnsV) {
dnsdata_t * t;
if (dnsV->dnsData == NULL) {
fprintf (stderr, "[WARN] - Got nothing [!!]\n");
return;
}
size_t i;
for (i = 0; i < dnsV->size; i++) {
t = &(dnsV->dnsData[i]);
printf("HOST ENCONTRADO: %s ====> IP: %s \n", (t->host), t->host_addr);
}
}