Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 36084  / 2 Years ago, sat, january 8, 2022, 4:56:52

Is it possible to determine the IP addresses of systems within a network using a bash script? And how?


More From » bash

 Answers
5

Install arp-scan (sudo apt-get install arp-scan) and add the following line to the script:



IPs=$(sudo arp-scan --localnet --numeric --quiet --ignoredups | grep -E '([a-f0-9]{2}:){5}[a-f0-9]{2}' | awk '{print $1}')


Now you have all the active IP addresses in the IPs variable.



Note: this will only work on a directly connected network, i.e. not accessed through a router.



PS: If you install gawk the command can be shortened to (thanks belacqua):



IPs=$(sudo arp-scan --localnet --quiet --ignoredups | gawk '/([a-f0-9]{2}:){5}[a-f0-9]{2}/ {print $1}')

[#30692] Monday, January 10, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
njuash

Total Points: 402
Total Questions: 125
Total Answers: 98

Location: Jersey
Member since Sun, Dec 4, 2022
1 Year ago
;