Skip to content

Commit 27d8d2d

Browse files
committed
updated install script to remove a debugging stop.
1 parent 4e16f43 commit 27d8d2d

2 files changed

Lines changed: 92 additions & 82 deletions

File tree

install.sh renamed to install

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ NC='\033[0m'
99
echo -e "${BLUE}== xpscan (Pro-Scanner) Setup ==${NC}"
1010

1111
# Checking if needed dependencies are installed
12-
for CMD in git cmake make; do
12+
for CMD in git cmake make criterion; do
1313
if ! command -v $CMD &>/dev/null; then
1414
echo -e "${RED}[x] ${CMD} not found, make sure it is installed before trying to install xpscan ${NC}"
15+
exit 1
1516
fi
1617
done
17-
exit 1
1818

1919
# 1. Detect Existing Installation
2020
CONFIG_DIR="$HOME/.config/.xpscan"
@@ -32,7 +32,7 @@ if [ "$IS_UPGRADE" = true ] && [ -f "$CONF_FILE" ]; then
3232
echo -e "${BLUE}[*] Preserving export path: ${EXPORT_PATH}${NC}"
3333
else
3434
# Redirection from /dev/tty ensures this works via curl | bash
35-
read -p "Enter default export directory [default: $HOME/xpscan/]: " EXPORT_PATH </dev/tty
35+
read -r -p "Enter default export directory [default: $HOME/xpscan/]: " EXPORT_PATH </dev/tty
3636
EXPORT_PATH=${EXPORT_PATH:-$HOME/xpscan/}
3737

3838
mkdir -p "$CONFIG_DIR"
@@ -46,7 +46,7 @@ echo -e "${BLUE}[*] Downloading latest source...${NC}"
4646
git clone https://github.com/sidatii/xpscan.git "$TEMP_DIR" &>/dev/null
4747

4848
cd "$TEMP_DIR" || exit
49-
mkdir -p build && cd build
49+
mkdir -p build && cd build || exit
5050

5151
echo -e "${BLUE}[*] Compiling...${NC}"
5252
cmake .. >/dev/null && make >/dev/null

src/main.cpp

Lines changed: 88 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -14,84 +14,94 @@ using namespace std;
1414

1515
#define THREAD_NUM 200
1616

17-
void print_usage() {
18-
std::cout << PINK << "Usage: xpscan <IP> [options]\n"
19-
<< NC << BLUE << "Options:\n"
20-
<< " --help Print this message\n"
21-
<< " --json Export results to [IP].json\n"
22-
<< " --txt Export results to [IP].txt\n"
23-
<< " --full Scan all 65535 ports\n"
24-
<< NC;
17+
void print_usage()
18+
{
19+
std::cout << PINK << "Usage: xpscan <IP> [options]\n"
20+
<< NC << BLUE << "Options:\n"
21+
<< " --help Print this message\n"
22+
<< " --json Export results to [IP].json\n"
23+
<< " --txt Export results to [IP].txt\n"
24+
<< " --full Scan all 65535 ports\n"
25+
<< NC;
2526
}
2627

27-
int main(int argc, char *argv[]) {
28-
// check if at least one arg is passed
29-
if (argc < 2 || std::strcmp(argv[1], "--help") == 0) {
30-
print_usage();
31-
return 1;
32-
}
33-
34-
// Validate the ip
35-
std::regex ip_regex(R"(^(\d{1,3}\.){3}\d{1,3}$)");
36-
if (!std::regex_match(argv[1], ip_regex)) {
37-
std::cerr << RED << "[x] Invalid IP address format." << NC << endl;
38-
return 1;
39-
}
40-
41-
// Instatiate user input struct
42-
struct UserInput input{};
43-
44-
// Parse args
45-
std::vector<std::string> args(argv + 2, argv + argc);
46-
47-
// Set IP attribute to the second arg passed
48-
input.ip = argv[1];
49-
50-
// Parse Flags
51-
bool exportJson = (find(args.begin(), args.end(), "--json") != args.end());
52-
bool exportTxt = (find(args.begin(), args.end(), "--txt") != args.end());
53-
bool fullScan = (find(args.begin(), args.end(), "--full") != args.end());
54-
55-
Printer::printHeader();
56-
57-
// Check for fullscan flag
58-
if (fullScan) {
59-
input.start_port = START_PORT;
60-
input.end_port = END_PORT;
61-
} else {
62-
std::cout << BLUE << "Enter start port:" << NC;
63-
std::cin >> input.start_port;
64-
std::cout << BLUE << "Enter end port:" << NC;
65-
std::cin >> input.end_port;
66-
}
67-
68-
// Instatiate the scanner class with params
69-
Scanner scanner(input.ip, THREAD_NUM);
70-
71-
// Record start time
72-
auto start = std::chrono::steady_clock::now();
73-
74-
// Proceed with the scanning logic
75-
scanner.scanRange(input.start_port, input.end_port);
76-
77-
// Record end time
78-
auto end = std::chrono::steady_clock::now();
79-
80-
// Calculate elapsed time
81-
std::chrono::duration<double> diff = end - start;
82-
std::cout << "\n"
83-
<< BLUE << "[!] Scan finished in " << diff.count() << "s" << NC
84-
<< std::endl;
85-
86-
Exporter exporter; // Uses default config path because i extracted the config file path as a parameter
87-
if (exportJson) exporter.saveToJson(input.ip, scanner.getResults());
88-
if (exportTxt) exporter.saveToText(input.ip, scanner.getResults());
89-
90-
if (!exportJson && !exportTxt) {
91-
std::cout << PINK
92-
<< "[!] No export flags set. Use --json or --txt to save results."
93-
<< NC << std::endl;
94-
}
95-
96-
return 0;
28+
int main(int argc, char* argv[])
29+
{
30+
// check if at least one arg is passed
31+
if (argc < 2 || std::strcmp(argv[1], "--help") == 0)
32+
{
33+
print_usage();
34+
return 1;
35+
}
36+
37+
// Validate the ip
38+
std::regex ip_regex(R"(^(\d{1,3}\.){3}\d{1,3}$)");
39+
if (!std::regex_match(argv[1], ip_regex))
40+
{
41+
std::cerr << RED << "[x] Invalid IP address format." << NC << endl;
42+
return 1;
43+
}
44+
45+
// Instatiate user input struct
46+
struct UserInput input{};
47+
48+
// Parse args
49+
std::vector<std::string> args(argv + 2, argv + argc);
50+
51+
// Set IP attribute to the second arg passed
52+
input.ip = argv[1];
53+
54+
// Parse Flags
55+
bool exportJson = (find(args.begin(), args.end(), "--json") != args.end());
56+
bool exportTxt = (find(args.begin(), args.end(), "--txt") != args.end());
57+
bool fullScan = (find(args.begin(), args.end(), "--full") != args.end());
58+
59+
Printer::printHeader();
60+
61+
// Check for fullscan flag
62+
if (fullScan)
63+
{
64+
input.start_port = START_PORT;
65+
input.end_port = END_PORT;
66+
}
67+
else
68+
{
69+
std::cout << BLUE << "Enter start port:" << NC;
70+
std::cin >> input.start_port;
71+
std::cout << BLUE << "Enter end port:" << NC;
72+
std::cin >> input.end_port;
73+
}
74+
75+
// Instatiate the scanner class with params
76+
Scanner scanner(input.ip, THREAD_NUM);
77+
78+
// Record start time
79+
auto start = std::chrono::steady_clock::now();
80+
81+
// Proceed with the scanning logic
82+
scanner.scanRange(input.start_port, input.end_port);
83+
84+
// Record end time
85+
auto end = std::chrono::steady_clock::now();
86+
87+
// Calculate elapsed time
88+
std::chrono::duration<double> diff = end - start;
89+
std::cout << "\n"
90+
<< BLUE << "[!] Scan finished in " << diff.count() << "s" << NC
91+
<< std::endl;
92+
93+
Exporter exporter; // Uses default config path because i extracted the config file path as a parameter
94+
if (exportJson)
95+
exporter.saveToJson(input.ip, scanner.getResults());
96+
if (exportTxt)
97+
exporter.saveToText(input.ip, scanner.getResults());
98+
99+
if (!exportJson && !exportTxt)
100+
{
101+
std::cout << PINK
102+
<< "[!] No export flags set. Use --json or --txt to save results."
103+
<< NC << std::endl;
104+
}
105+
106+
return 0;
97107
}

0 commit comments

Comments
 (0)