In this lab you will write a bash script that uses scapy and arping to perform A
ID: 3870612 • Letter: I
Question
In this lab you will write a bash script that uses scapy and arping to perform ARP scan of a computer network. The IP addresses of the computers to be scanned will be provided in a file named network.txt. Your script will take as arguments the network.txt file, the timeout and the number of packets to be send. The output of your script will be the IP addresses and MAC addresses of the live hosts only.
Example:
If you run:
sh script.sh network.txt 2 3
the output should look like:
Scaning results for scapy ip address mac adress
Scaning results for arping Ip address mac adress
Deliverables: Submit you bash file; make sure you include any direction on how to use you script in a readme file(must run on Kali Linux on the lab machines).
Explanation / Answer
Code:
#!/bin/bash
# Does an arping and prints ip and mac if it is up.
arpScanIp() {
# run arping command with given params
arpingRes=`arping -b -I eth0 $1 -c $2 -w $3`;
# Grep and sed the response from arping to get total number of successful
# pings sent.
numberOfResponses=`echo $arpingRes |
grep -oP "Received (d+)" |
sed -n -e 's/Received ([[:alnum:]]+).*//p'`;
macAddress=`echo $arpingRes | grep -oP -m 1 "[((w{2}:){5}w{2})]" | head -1`;
# if number of resposes is equals to number of resposes we asked it to send
if [ "$numberOfResponses" -eq "$2" ]
then
# echo results.
echo "Scaning results for arping: $ip - $macAddress"
fi
}
# =~=~=~=~=~= MAIN =~=~=~=~=~=
# incase first, second or third argument to script is empty.
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]
then
# Show usage
echo "Usage: bash <script_name> <number_of_pings> <ping_timeout>"
else
# else read file and
while IFS='' read -r ip || [[ -n "$ip" ]]; do
# arping on each given ip address
arpScanIp $ip $2 $3
done < "$1"
fi
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.