Skip to content

Instantly share code, notes, and snippets.

@lancelakey
Created August 11, 2011 09:12
Show Gist options
  • Save lancelakey/1139218 to your computer and use it in GitHub Desktop.
Save lancelakey/1139218 to your computer and use it in GitHub Desktop.
Detect or Find Duplicate IP Addresses
#!/usr/bin/env bash
# This script was written for and works on Mac OS X
# I have to use sudo to run arping on Mac OS X
# I believe the options for arping on linux are a little different. I believe you use -D for duplicate IP detection instead of -d but that's from memory and you should check.
echo "Starting duplicate IP detection with sudo arping!"
for i in {1..254};
do
sudo arping -q -d -c 2 192.168.1.$i; [ $? -ne 0 ] && echo "192.168.1.$i duplicate";
done
@flores
Copy link

flores commented Aug 11, 2011

nice @lancelakey! only an idea:

if ! sudo arping -q -d -c 2 192.168.1.$i ; then
echo 192.168.1.$i duplicate
fi

may be more readable than the one liner capturing exit status of the exit status. ifs containing commands still operate on true or false.

Also, maybe do $? -eq 1 or whatever the proper exit code is. I'm just thinking command not found is 127 but would print duplicate.

just ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment