I finally got around to releasing a small network utility called netwatch:
https://github.com/johnscillieri/netwatch
netwatch scans your network for hosts, lets you label them, and shows you the last time they were seen:
Scanning 192.168.11.0/24...
Label IP Address MAC Address OUI Last Seen
1. Router 192.168.11.1 de:ad:be:ef:00:00 Actiontec 1m
2. 192.168.11.2 b4:75:0e:00:ff:ff Belkin 1m
3. John's Phone 192.168.11.4 64:bc:0c:00:dd:11 LG 1m
4. Serenity 192.168.11.6 00:24:e8:00:aa:aa Dell <1m
5. Nest 192.168.11.7 18:b4:30:00:bb:bb Nest 1m
6. Emily's Phone 192.168.11.8 60:92:17:00:cc:cc Apple 3m
7. Alexa 192.168.11.18 0c:47:c9:00:dd:dd Amazon 1m
8. 192.168.11.23 ec:1a:59:00:00:11 Belkin <1m
9. IP-STB 192.168.11.100 f4:5f:d4:00:12:34 Cisco SPVTG <1m
10. IP-STB2 192.168.11.101 00:21:be:00:56:78 Cisco SPVTG <1m
Press 1-10 to assign a label. Press q to quit.
Right now it only supports Linux but I can add MacOS & Windows if there's interest.
Let me know if you find it useful or have any comments or questions (tool, code, or otherwise).
A little improvement - use int -> string table in oui.nom instead of string -> string. This saves ~600kb in resulting binary.
https://github.com/scriptum/netwatch/commit/f0925bc04153d83eec7d23b98669b6486cb1264f
P.S. It displays Zyxel router as "5420". Is it ok?
P.P.S. Improvement suggestion - assign labels automatically using DNS or mDNS.
Good thinking on the int->string table and thanks for the suggestion! I'll implement that for 1.1.
Regarding your Zyxel mapping, it looks like the folks at http://linuxnet.ca/ieee/oui/nmap-mac-prefixes updated their table and fixed your problem. If you "make cleanall" (or wait for the next release of netwatch) you should have the correct mapping.
I thought about the DNS lookup for unlabeled hosts (netwatch TODO) and agree it's a good idea (though I probably won't color them differently as I originally considered). Should be easy enough to include for 1.1 as well.
Thank you SO much for the feedback and I hope you like netwatch.
@federico3: Trying to! :) I'm doing Linux first and unfortunately it's only when I get some free time. Help & PRs are welcome!
The idea (from @endragor) is to rip out most of the low-level interface/network stuff that's in netwatch and use a psutil library instead.
As an aside, Nim makes it really nice to port the psutil Python code. The original library has shared Python code that calls platform-specific Python code that then calls platform-specific C code. Nim doesn't need any of that extra C layer! I'm curious to see the LOC comparison after it's done. Not sure I'll get there thought b/c the author moves fast ;)
Is there a way to replace this boilerplate code in Nim?
result[name] = NetIO( bytes_sent:bytes_sent, bytes_recv:bytes_recv,
packets_sent:packets_sent, packets_recv:packets_recv,
errin:errin, errout:errout,
dropin:dropin, dropout:dropout )
Just interesting.
Removed the temp variable declarations in the latest check in.
Looks like this now:
proc net_io_counters*(): TableRef[string, NetIO] =
## Return network I/O statistics for every network interface
## installed on the system as a dict of raw tuples.
result = newTable[string, NetIO]()
for line in lines( PROCFS_PATH / "net/dev" ):
if not( ":" in line ): continue
let colon = line.rfind(':')
let name = line[..colon].strip()
let fields = mapIt( line[(colon + 1)..len(line)].splitWhitespace(), parseInt(it) )
result[name] = NetIO( bytes_sent: fields[8],
bytes_recv: fields[0],
packets_sent: fields[9],
packets_recv: fields[1],
errin: fields[2],
errout: fields[10],
dropin: fields[3],
dropout: fields[11] )