Last active
August 4, 2021 12:06
-
-
Save ixs/24545ad8715a5c3915e0585418635fed to your computer and use it in GitHub Desktop.
IP Finder als kleine Programmierübung
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 | |
set -euo pipefail | |
# IP Finder als kleine Programmierübung | |
NAMED=/var/named/data | |
NETZ="${1:-}" | |
if [ -z "$NETZ" ]; then | |
echo "$0 [netz/prefix]" | |
exit 1 | |
fi | |
function ip2long() { | |
IP="$1" | |
echo $(python -c 'import socket; import struct; print(struct.unpack("!L", socket.inet_aton("'$IP'")))[0]') | |
} | |
function long2ip() { | |
LONG="$1" | |
echo $(python -c 'import socket; import struct; print(socket.inet_ntoa(struct.pack("!L", '$LONG')))') | |
} | |
eval $(ipcalc -bn $NETZ) | |
START=$(ip2long $NETWORK) | |
END=$(ip2long $BROADCAST) | |
IP=$((START+1)) | |
while [ $IP -lt $((END-1)) ]; do | |
IPt=$(long2ip $IP) | |
regexp=$(echo $IPt | sed 's/\./\\\./g;') | |
grep -R -E "$regexp\$" "$NAMED" || true | |
IP=$(($IP + 1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment