if [[ $UID != 0 ]]; then
	echo "Please switch to root-user"
	exit
fi

source /etc/os-release

if command -v apt; then
	pkgmgr=apt
elif command -v dnf; then
	pkgmgr=dnf
fi

if ! command -v arping 2>&1 >/dev/null; then
		$pkgmgr -y -q install arping
fi

if ! command -v ipcalc 2>&1 >/dev/null;	then
		$pkgmgr -y -q install ipcalc-ng
                if [[ $RT == 1 ]]; then
                        $pkgmgr install ipcalc
                fi
fi	

ip -o -4 addr show | sed -e '/UNKNOWN/d' -e '/DOWN/d' -e '/host lo/d' | while read -r a b c d e;

	do
		IPADDR=$(ipcalc-ng -a --no-decorate $d 2> /dev/null)
		GATEWAY=$(ipcalc-ng --minaddr  --no-decorate $d 2> /dev/null)
		if [[ $IPADDR == "" ]] & [[ $GATEWAY == "" ]]; then
			IPADDR=$(ipcalc $d | grep ^Address | awk '{print $2}')
			GATEWAY=$(ipcalc $d | grep ^HostMin | awk '{print $2}')
		fi
		echo arping -c 1 -i $b -S $IPADDR $GATEWAY 
		arping -c 1 -i $b -S $IPADDR $GATEWAY 2>&1>/dev/null ; RT=$?
		if [[ $RT == 1 ]]; then
			arping -c 1 -I $b -s $IPADDR $GATEWAY 2>&1>/dev/null 
		fi
	done