There's one problem you hadn't considered, and that is that mIRC now [officially] allows multiple server entries for different groups to utilize the same server address/ip. Using $server($servertarget).group will potentially reveal one of the other groups besides the one you're actually connected to. This is especially true if you configure ZNC for multiple networks, and create groups in mIRC for each such network. Same IP, same $servertarget, different network connection dependent on password, different $servergroup

Also, if you manually connect to a server via command /server <address> then you won't necessarily be using those group settings. I think you did once upon a time, but not anymore.

Today: There is no proper way to read all of the Current/Cached connection properties directly. Only to infer them through incorrect assumption.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!