Olipro / ipset

ipset from the NetFilter project
GNU General Public License v2.0
15 stars 6 forks source link

Feature request: display sets that match IP #7

Open fraternl opened 5 years ago

fraternl commented 5 years ago

I know that I can test an IP against a set, but I would like to be able to only give an IP and let ipset return all the sets that match. I wrote a wrapper that does this, but I think it would be useful if it supported this natively (and faster).

ipset setmatch 192.168.1.1

ipsetmatch

#!/bin/bash

TMPDIR=`mktemp -t -d ${0//*\/}.XXXXXXXXXX`
ipset -n list >${TMPDIR}/ipsets

while read IPSET ; do
  ipset test ${IPSET} $1 2>/dev/null && echo ${IPSET}
done<${TMPDIR}/ipsets

rm -r ${TMPDIR}