Here's a simple $comchanmask I slapped together. It relies on the Internal Address List (IAL), so if you want it to always work 100% accurately you'll need to fill your IAL upon joining channels by issuing a command like /who #channelname. Note that I only just wrote this so you should probably test it a bit to make sure it works correctly before doing anything important with it.

Code:
alias comchanmask {
  ; Usage: $comchanmask(hostmask, N)
  var %i = 1, %chans, %parm2 = $int($2), %c
  while $chan(%i) {
    %c = $v1
    if ($ialchan($1, %c, 0)) {
      %chans = $addtok(%chans, %c, 32)
      if ($numtok(%chans, 32) == %parm2) return %c
    }
    inc %i
  }
  if (%parm2 == 0) return $numtok(%chans, 32)
}


As for the $comnet, I'm not sure exactly what you're looking for. Do you want it to take a nickname and return common networks based on nicks which you can see (ie. that you share at least one channels with on a network) or do you want it to actually check if that nick exists anywhere on that network (if so, it won't be possible to write an identifier that does that).


Spelling mistakes, grammatical errors, and stupid comments are intentional.