0

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.

rannday
  • 11

1 Answers1

0

Stéphane's link gave me my answer.

Set Complement
$ comm -23 <(sort set1) <(sort set2)
# outputs elements in set1 that are not in set2

rannday
  • 11