Skip to content

Instantly share code, notes, and snippets.

@wulfgarpro
Created September 11, 2024 01:47
Show Gist options
  • Save wulfgarpro/15b2de6c1145625b63b1df3fc31e6b6e to your computer and use it in GitHub Desktop.
Save wulfgarpro/15b2de6c1145625b63b1df3fc31e6b6e to your computer and use it in GitHub Desktop.
getips
#!/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