The nireport command can be used to list all of the groups in a NetInfo structure. To use nireport, you will need to specify the domain and a directory (in that order). Optionally, you can also specify a timeout for the query (-T) and whether or not the domain should be treated as tagged (-t). So if your NetInfo domain were local then the following would show all of the groups in a 10.3 Server-based Open Directory:
nireport . /groups
The equivalent in 10.4 and up would then be:
dscl . -list /Groups
Or for users:
dscl . -list /Users
To then show all of the users in a group you could query niutil and then parse out the membership (this could be done in Workgroup Manager as well):
niutil -read . /NetInfo/root/Groups
If you’re looking for gid then it might be a little easier though, as you can use nifind:
nifind -v /users/gid=20