Created
September 11, 2024 01:47
-
-
Save wulfgarpro/15b2de6c1145625b63b1df3fc31e6b6e to your computer and use it in GitHub Desktop.
getips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 [N] [IPv4]" | |
exit 1 | |
fi | |
N=$1 | |
IP=$2 | |
IFS='.' read -r octet1 octet2 octet3 octet4 <<< "$IP" | |
if [ "$octet4" -lt 0 ] || [ "$octet4" -gt 255 ]; then | |
echo "Invalid IP address." | |
exit 1 | |
fi | |
if [ "$N" -eq 0 ] || [ "$octet4" -eq 0 ]; then | |
exit 0 | |
fi | |
first_usable=1 | |
count=0 | |
for i in $(seq $first_usable 254); do | |
current_ip="$octet1.$octet2.$octet3.$i" | |
echo "$current_ip" | |
count=$((count + 1)) | |
if [ "$i" -eq "$octet4" ] || [ "$count" -eq "$N" ]; then | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment