-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
87 lines (82 loc) · 2.41 KB
/
main.c
File metadata and controls
87 lines (82 loc) · 2.41 KB
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
84
85
86
87
#include "ft_nmap.h"
void print_help()
{
printf("Help Screen\n");
printf("Usage: ft_nmap [--ports [NUMBER/RANGED]] --ip IP_ADDRESS [--speedup [NUMBER] [--scan [TYPE]]\n");
printf("or: ft_nmap [--ports [NUMBER/RANGED]] --file FILE [--speedup [NUMBER] [--scan [TYPE]]\n");
printf("--help Print this help screen\n");
printf("--ports Ports to scan (eg: 1-10 or 10)\n");
printf("--ip ip addresses to scan in do fromat (IPv4)\n");
printf("--file File name containing IP addresses to scan\n");
printf("--speedup [250 max] number of parallel threads to use\n");
printf("--scan SYN/NULL/FIN/XMAS/ACK/UDP\n");
exit(0);
}
int main(int argc, char **argv)
{
int i;
bool ipaddr;
t_input input;
i = 1;
ipaddr = false;
input.scans = NULL;
input.ipaddr = NULL;
input.ports = NULL;
input.port_count = 0;
input.thread_count = 0;
if (argc == 1 || (argc == 2 && !strcmp("--help", argv[1])))
print_help();
if (argc % 2 == 0)
print_help();
// loop through the args
while (argc > i)
{
// printf("hoho %s\n", argv[i]);
if (!strcmp(argv[i], "--ip")) // this one handles "--ip"
{
// this one handle the duplication usage of --file and --ip
if (ipaddr)
{
printf("Error: only use --file or --ip\n");
print_help();
}
if (!parse_ip(argv[i + 1], &input))
print_help();
ipaddr = true;
}
else if (!strcmp(argv[i], "--file")) // this one handles "--file"
{
// this one handle the duplication usage of --file and --ip
if (ipaddr)
{
printf("Error: only use --file or --ip\n");
print_help();
}
if (!parse_ip_file(argv[i + 1], &input))
print_help();
ipaddr = true;
}
// this one handles "--speedup" pay attention to the &&
else if (!strcmp(argv[i], "--speedup") && parse_speedup(argv[i + 1], &input));
// this one handles "--scan" pay attention to the &&
else if (!strcmp(argv[i], "--scan") && parse_scan(argv[i + 1], &input));
// this one handles "--ports" pay attention to the &&
else if (!strcmp(argv[i], "--ports") && parse_ports(argv[i + 1], &input));
else
print_help(); // handle mistaken args
// we skip the option's value and get to the next key
i += 2;
}
// checks if the only required field is there
if (!ipaddr)
print_help();
if (!input.scans)
input.scans = return_all_scans();
if (!input.ports)
{
input.ports = return_default_ports();
input.port_count = node_counter(input.ports);
}
nmap_loop(&input);
return 0;
}