Reverse..



Differences

This shows you the differences between two versions of the page.

Link to this comparison view

networks:gratuitous_arp [2018/04/06 04:18] (current)
ga1axy created
Line 1: Line 1:
 +
 +
 +<file bash send_gratuitous_arp.sh>​
 +#!/bin/bash
 +
 +help()
 +{
 +  echo "​Usage:​ $0 [count] [interval]"​
 +  exit 1
 +}
 +
 +if [ $# -ne 2 ]
 +then
 +  help
 +fi
 +
 +if echo $1 | grep -qe "​^[-\?​[0-9]\+\.\?​[0-9]*$";​ then
 +  COUNT=$1
 +else
 +  help
 +fi
 +
 +if echo $2 | grep -qe "​^[-\?​[0-9]\+\.\?​[0-9]*$";​ then
 +  INTERVAL=$2
 +else
 +  help
 +fi
 +
 +hash ip 2>/​dev/​null || { echo >&2 "I require [ip] but it's not installed. ​ Aborting.";​ exit 1; }
 +hash arping 2>/​dev/​null || { echo >&2 "I require [arping] but it's not installed. ​ Aborting.";​ exit 1; }
 +
 +COUNTER=1
 +
 +while [ $COUNTER -le $COUNT ]; do
 +  echo =================================================================
 +  date
 +  echo "​COUNT=$COUNTER/​$COUNT,​ INTERVAL=$INTERVAL"​
 +  echo =================================================================
 +  for iface in $(ip -o link show | grep -v '​NOARP'​ | grep -v '​LOOPBACK'​ | awk -F': ' '​{print $2}'); do 
 +    addrs=$(ip -o -4 addr list $iface | awk '​{print $4}' | cut -d/ -f1)
 +    for addr in $addrs; do
 +      if [ -n "​$addr"​ ]; then
 +        echo "Send Gratuitous ARP Request/​Reply Mode for ($iface) $addr"
 +        garp_res_command="​arping -U -I $iface $addr -c 1 -q"
 +        eval $garp_res_command
 +        garp_req_command="​arping -A -I $iface $addr -c 1 -q"
 +        eval $garp_req_command
 +      fi
 +    done
 +  done
 +  let COUNTER=COUNTER+1
 +  sleep $INTERVAL
 +done
 +
 +
 +#Usage: arping [-fqbDUAV] [-c count] [-w timeout] [-I device] [-s source] destination
 +#  -f : quit on first reply
 +#  -q : be quiet
 +#  -b : keep broadcasting,​ don't go unicast
 +#  -D : duplicate address detection mode
 +#  -U : Unsolicited ARP mode, update your neighbours
 +#  -A : ARP answer mode, update your neighbours
 +#  -V : print version and exit
 +#  -c count : how many packets to send
 +#  -w timeout : how long to wait for a reply
 +#  -I device : which ethernet device to use (eth0)
 +#  -s source : source ip address
 +#  destination : ask for what ip address
 +
 +#echo 1 > /​proc/​sys/​net/​ipv4/​ip_nonlocal_bind
 +</​file>​