feature: better print output
fix: remove useless mutex for the routine start
This commit is contained in:
69
src/print.c
69
src/print.c
@ -1,21 +1,61 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "parsing.h"
|
||||
#include "response.h"
|
||||
#include "scan.h"
|
||||
|
||||
void print_usage(void)
|
||||
{
|
||||
// TODO
|
||||
printf("--help: Print this help screen\n");
|
||||
printf("--ports: ports to scan (eg: 42-69 or 666)\n");
|
||||
printf("--ip: ip address to scan in dot format\n");
|
||||
printf("--file: File name containing IP addresses to scan\n");
|
||||
printf("--speedup: [250 max] number of parallel threads to use\n");
|
||||
printf("--scan: NULL/SYN/FIN/XMAS/ACK/UDP\n");
|
||||
}
|
||||
|
||||
static void print_port_state(uint16_t port, e_scantype type, const struct response * response)
|
||||
void print_config(const struct scan *general, const char *hosts_path,
|
||||
uint8_t nb_threads)
|
||||
{
|
||||
printf("Scan configurations\n");
|
||||
if (hosts_path)
|
||||
printf("Target hosts list filename: %s\n", hosts_path);
|
||||
else
|
||||
printf("Target ip address: %s\n", general->dest_addr);
|
||||
if (general->port_start != general->port_end)
|
||||
printf("Number of scans to be performed: %d\n",
|
||||
general->port_end - general->port_start + 1);
|
||||
printf("Scans to be performed: ");
|
||||
if (general->type == SCAN_ALL)
|
||||
for (e_scantype type = SCAN_NULL; type < SCAN_ALL; type++)
|
||||
printf("%s ", types_str[type]);
|
||||
else
|
||||
printf("%s", types_str[general->type]);
|
||||
printf("\n");
|
||||
if (nb_threads > 1)
|
||||
printf("No of threads: %d\n", nb_threads);
|
||||
}
|
||||
|
||||
bool is_port_opened(const e_state states[6], e_scantype type)
|
||||
{
|
||||
if (type == SCAN_ALL) {
|
||||
for (e_scantype i = SCAN_NULL; i < SCAN_ALL; i++)
|
||||
if (states[i] == OPENED)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return states[type] == OPENED;
|
||||
}
|
||||
|
||||
static void print_port_state(uint16_t port, e_scantype type,
|
||||
const struct response *response)
|
||||
{
|
||||
if (type != SCAN_ALL && response->states[type] == CLOSED)
|
||||
return;
|
||||
printf("%-5d %-12s ", port,
|
||||
response->service ? response->service : "Unassigned");
|
||||
if (response->service)
|
||||
free(response->service);
|
||||
if (type == SCAN_ALL)
|
||||
for (e_scantype i = SCAN_NULL; i < SCAN_ALL; i++)
|
||||
printf("%s(%s) ", types_str[i],
|
||||
@ -30,8 +70,21 @@ void print_host_results(const struct scan *general, double scan_time)
|
||||
{
|
||||
printf("Scan took %lf secs\n", scan_time);
|
||||
printf("IP address: %s\n", general->dest_addr);
|
||||
printf("Open ports:\n");
|
||||
for (uint16_t port = general->port_start; port < general->port_end; port++) {
|
||||
print_port_state(port, general->type, &general->responses[port - general->port_start]);
|
||||
printf("Opened ports:\n");
|
||||
for (uint16_t port = general->port_start; port < general->port_end;
|
||||
port++) {
|
||||
const struct response *response =
|
||||
&general->responses[port - general->port_start];
|
||||
if (is_port_opened(response->states, general->type))
|
||||
print_port_state(port, general->type, response);
|
||||
}
|
||||
printf("\n");
|
||||
printf("Closed/filtered/unfiltered ports:\n");
|
||||
for (uint16_t port = general->port_start; port <= general->port_end;
|
||||
port++) {
|
||||
const struct response *response =
|
||||
&general->responses[port - general->port_start];
|
||||
if (!is_port_opened(response->states, general->type))
|
||||
print_port_state(port, general->type, response);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user