Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.
/ hostsdb Public archive

A very simple tool that parses hosts files into a SQLite 3 database

License

Notifications You must be signed in to change notification settings

impermaxvict/hostsdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

hostsdb

A very simple tool that parses a single hosts file into a SQLite 3 database

(Works only on Linux!)

Usage:

hostsdb <hosts-file>

The resulting database file is called hosts.sqlite3 and contains a single table called rules with two columns called ip_address and host_name.

Example:

hostsdb /etc/hosts

Installation

You need GCC and SQLite 3 in your standard path. (On Arch Linux you can install it with # pacman -Syu gcc sqlite) Then clone this repository and run make. That's it!

Convert the database back to a hosts file:

sqlite3 hosts.sqlite3 "SELECT ip_address || CHAR(9) || host_name FROM rules ORDER BY host_name;" | expand -t 24 > hosts

Convert the database to a domain name list:

sqlite3 hosts.sqlite3 "SELECT DISTINCT host_name FROM rules ORDER BY host_name;" > domains

Other examples:

# Get all .org domains in the db (1 per line)
sqlite3 hosts.sqlite3 "SELECT DISTINCT host_name FROM rules WHERE host_name LIKE '%.org' ORDER BY host_name;"

# Count the number of .gov domains in the db
sqlite3 hosts.sqlite3 "SELECT DISTINCT COUNT(1) FROM rules WHERE host_name LIKE '%.gov';"

About

A very simple tool that parses hosts files into a SQLite 3 database

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published