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
Is it possible to determine the IP addresses of systems within a network using a bash script? And how?
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}')