running script when detecting access to net

running script when detecting access to net

Post by Michael B. Alle » Fri, 25 Aug 2000 04:00:00



Hi!

Is there a daemon that can watch the tcp traffic on the local machine and
run an arbitrary script if specific subnets or addresses are requested? Such
a daemon might have a config file that looks like routing table entries but
with a destination, genmask, script to run, and lock file.

192.168.0.0   255.255.0.0    null
/some/file/that/always/exists
172.17.0.0    255.255.0.0    /etc/ppp/ppp-on-work
/var/run/ppp-on-work.lock
0.0.0.0       0.0.0.0        /etc/ppp/ppp-on         /var/run/ppp-on.lock

So if I launch Netscape and try to access a site like someplace.work.com dns
will see a zone file for 'work.com' and decide to query my dns server at
work which will no doubt begin with 172.17 and therefore trigger pppd to
dial work(actually I don't know for sure if zone files work this way, I'm
making this up as I go along :~). If I try to access Yahoo.com, my machine
will not recognize the domain and try to query my isp's dns server which
would match the default entry of 0.0.0.0 and dial my isp. If the daemon runs
a script it creates a lock file so it knows to stop listening.

Get it? Can I do this?

I'm starting to get pretty good at c but I haven't done any sockets
programming with it. How hard could it be to write such a 'netdetectd'
daemon? I would think this might be a pretty useful little utility. Any
ideas?

Thanks,
Mike