Parsing IANA Port Assignments into TOML Config File

I’m generally much more of a sysadmin than a programmer, but I’m working on scripting network deployments, and I wanted to get all the IANA port assignments into a config file that I could reference for NAT/Firewall config.

So I wrote a script in Ruby that takes the XML format of the IANA port assignments from their website and parses it into what is, for me at least, a more useful format (TOML).

The TOML config file ends up being kind of absurdly long, so if anyone has any other format suggestions, let me know. The little Ruby program could be easily adapted to spit the information out differently.

Also, any critiques of my programming would be very welcome. I mostly live in bash, so I’m out of my element.

https://gist.github.com/o0-o/e8ac5d2c374ba505734734b795a74ca4

https://gist.github.com/o0-o/981310698649c95bd366f806b2050e63

Whats wrong with the /etc/services file?

1 Like

I figured if I was going to have to parse out of /etc/services, I might as well just get everything from the source. I’m already storing other network information (subnet/vlan definitions) in TOML files, so it makes sense for me.

That said, I did totally forget that getent has a services option to pull services/protocols (presumably out of /etc/services). It seems to only pull the first match though…

/etc/services can also vary between operating systems. Ideally, my admin scripts will be portable across different OS’s, so this keeps it consistent.

1 Like