ip-extractor.sh is a Bash script designed to extract IP addresses from any text input via the nano editor. It processes the input, saves clean IP lists into several formats, and provides immediate feedback in the console.
- Bash-compatible environment (Linux, macOS, WSL, etc.)
nanoeditor installed- Standard Unix tools:
grep,sort,tr,cat,rm,sed, etc.
-
Run the script:
./ip-extractor.sh
-
On first run, a file called
loadwill be opened innano. Paste your raw text (e.g., log files, traceroutes, firewall logs). -
Save and exit (
Ctrl + O,Enter,Ctrl + X). -
The script will:
- Extract all non-localhost IPv4 addresses
- Save them to a file called
hosts - Remove duplicates
- Create two additional files:
hostcom: IPs in a comma-separated formatchost: IPs in a space-separated format
- Display the final list of IPs in console
- Inform how many IPs were found
| File | Description |
|---|---|
hosts |
Unique extracted IP addresses, one per line |
hostcom |
Same IPs as in hosts, comma-separated |
chost |
Same IPs as in hosts, space-separated |
load |
Temporary input file (deleted after run) |
loadlast |
Copy of last processed input |
- Clean parsing: skips
127.*.*.*and non-IP lines - Visual feedback (
β,Done!) during processing - Duplicate removal via
sort -u - Auto-relaunches itself if
loadfile is empty or missing - Multi-format output: plain, comma, and space-separated
- The script only works with IPv4 addresses.
- Edit the regex in
grepif you want to support other formats or behaviours. - You can comment or customise the
JobFinmessages for quieter output.
This is a lightweight utility meant for quick daily tasks. Feel free to submit enhancements, especially:
- IPv6 support
- GUI-based input (e.g. with
zenity) - Output to JSON or CSV