Engineering/2024/Active
quickcmd
A simple command line tool to run commands quickly, made with C.
Overview
quickcmd is a tiny interactive shell written in C: it runs a read-eval loop that accepts one built-in command per line and executes a matching function. It's a small systems-programming exercise more than a production tool — the interesting part is that its two "real" commands are implemented twice, once against POSIX networking APIs and once against the Windows IP Helper API, selected at compile time with #ifdef _WIN32 guards.
Key Features
- Interactive loop — prompts with
Enter the Command:and reads input viascanfuntil you typeexit ipaddr— lists local network adapter names and IPv4 addresses; usesgetifaddrs/inet_ntopon Linux/macOS andGetAdaptersInfofrom the Windows IP Helper API (iphlpapi) on Windowshostname— prints the machine's hostname viagethostname(), wrapped inWSAStartup/WSACleanupon Windowshelp— lists the available commands- Cross-platform build — the same
main.c/cmd_functions.ccompile on both platforms; the Windows build linksws2_32andiphlpapi
Installation
git clone https://github.com/chethanyadav456/quickcmd.git
cd quickcmdA C compiler (GCC) is required. On Windows, the project's docs point to MinGW for GCC.
Build and run with the provided scripts, which compile with gcc and immediately launch the resulting binary:
# Linux / macOS
sh run.sh
# Windows
run.cmdrun.sh runs gcc -Wall -Wextra -g -o outputs/quickcmd main.c cmd_functions.c; run.cmd runs the Windows equivalent linking -liphlpapi -lws2_32.
Usage
Enter the Command: help
Available commands:
ipaddr - Display the IP address
help - Show this help message
hostname - Display the hostname
exit - Exit the programAny input that doesn't match a known command prints Invalid Command! Type "help" for more commands.