Sample Header Ad - 728x90

Comparing Sets with 'comm'

0 votes
1 answer
287 views
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: https://unix.stackexchange.com/questions/104837/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}/_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  "${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.
Asked by rannday (11 rep)
Jun 15, 2022, 04:49 PM
Last activity: Jun 15, 2022, 07:54 PM