Going from a dnsmasq log to a hosts file

So dnsmasq is nice, but nicer still is a hosts file (or at least I think so), though occasionally ip’s do change and you have to keep that in mind. But here’s a clever one that goes from a dnsmasq log to a hosts file.

\grep reply dnsmasq.log|\grep -Ev “CNAME|NODATA”|cut -c 38-100|awk ‘{print $3” “$1}’|sort -k 2|uniq -f 1|sort -g

This fetches all the addresses that you had to lookup, formats for hosts file, removes duplicates, and sorts. And you can set any adservers to 127.0.0.1 or your favorite not going to pull up any ads webserver.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: