#!/usr/bin/env sh

# Clean the ARP cache
# Run as root

if [ "$(id -u)" != "0" ];then
   echo "Run this script as root."
   exit
fi
ARP_TABLE="$(arp -an | awk '{ print $7 $2 }' | tr '(' ' ' | tr ')' ' ' | sed 's|\([^[:space:]]\) \([^[:space:]]\)|\1 -d \2|g' | sed 's/^/-i /')"
IFS_OLD="$IFS"
###IFS="$(printf '\n')"
# https://stackoverflow.com/questions/49701041/bash-strips-n-character-when-using-newline-delimiter
IFS='
'
for rm_entry in $ARP_TABLE; do
    printf "%s" "$rm_entry" | xargs arp
done
IFS="$IFS_OLD"
