I would have the portscanner generate some kind of output which can be read by another program running inparallel, or another function of the same program.

You could then use iptables, in...