Trying to get a list of available IP addresses based off all usable IPs in a range when compared to a device's ARP table.
Basing what I'm doing with comm
on this discussion: Intersection of two arrays in BASH
Creating ranges of IPs to compare against - e..g 192.168.20.0/23
RANGE1=(192.168.20.{2..255})
RANGE2=(192.168.21.{0..254})
RANGE=("${RANGE1[@]}" "${RANGE2[@]}")
printf '%s\n' "${RANGE[@]}" | LC_ALL=C sort > "${IPSETS_DIR}/<city-alias>_set.txt"
$1 is an IP of a network device. OID is basically a device's ARP table. GREP_SEARCH example: "192.168.20|192.168.30|192.168.55"
$(which snmpbulkwalk) -v2c -c <community-string> "${1}" .1.3.6.1.2.1.4.35.1.4 > "${RESULTS_FILE}"
STRIPPED_RESULTS=( $(cut -d\" -f2 "${RESULTS_FILE}" | egrep -w "(^|\s)${GREP_SEARCH}") )
printf "%s\n" "${STRIPPED_RESULTS[@]}" | LC_ALL=C sort > "${STRIPPED_FILE}"
The walk returns results such as:
IP-MIB::ipNetToPhysicalPhysAddress.118161416.ipv4."X.X.X.X" = STRING: XX:XX:XX:XX:XX:XX
I then compare using the below. $1 is city-alias.
$(which comm) -13 "${STRIPPED_FILE}" "${IPSETS_DIR}/${1}_set.txt" > "${DIR}/${1}_stored_results.txt"
This MOSTLY works, but I'm still getting IPs that are in use. Not sure what I'm missing.
$(which comm)
is a really weird statement. Why not jusecomm
? (Likewise elsewhere; you really don't needwhich
like this - just use the command.) – Chris Davies Jun 15 '22 at 21:18PATH
, so there is no reason to use it. Ifcomm
fails, so will$(which comm)
. Besides, there is only a handful of locations that command could normally be installed, most likely /usr/bin. – Vilinkameni Jun 16 '22 at 08:01