Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 36083  / 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
njuash questions
Wed, Jun 8, 22, 11:53, 2 Years ago
Wed, Nov 30, 22, 11:42, 1 Year ago
Mon, May 30, 22, 04:33, 2 Years ago
Mon, Apr 10, 23, 03:40, 1 Year ago
;