1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
There are two kinds of people in this world. Those who use just one single
smartphone for all their information technology needs, and those who suddenly
find themselves with more devices than they can keep track of without having
information about them written down somewhere.
If you are anything like me, sharing home with a couple of actively used
laptops, several smartphones, document and label printers, physical servers,
virtual servers and IoT things doing all kinds of weirdness, then just maybe
hisgle might be helpful to you too.
I've implemented hisgle (Host Inventory Script, Go Learning Experience) having
no less than 131 devices with individual mac addresses. Remembering exactly
where all of them were networkwise was becoming a challenge, so I put them all
in a database with the following structure:
CREATE TABLE devices (name, mac, interface);
CREATE TABLE addresses (mac, vlan, ipv4);
CREATE TABLE aliases (alias, target);
CREATE TABLE networks (vlan, description TEXT, ipv4);
Invoking hisgle generates ethers and hosts files which can be read directly by
dnsmasq on e.g. OpenWRT routers.
A typical command line would be:
hisgle --database=/somewhere/devices.db hosts 4 5 104
Above line would generate a hosts file for vlan:s 4, 5 and 104. You might want
to create a script which generates, copies and reloads hosts and ethers files
for all your routers. That's what the script I run whenever updating my list
of devices does.
Wanting to try using the Go language for a something helped giving a name to
this script. This is the first time I attempt writing something at all in Go.
I'm sure there are heaps of things which could be improved, but I'm happy for
now with a script which does what I need.
|