If you're writing an application to do this, why wouldn't you just use the socket API to attempt to communicate over the given port? If it's accepted, you know the port is in use. If it times-out, it's being blocked by a firewall. If the connection is refused, you know it's not in use.
Of course, this only works for TCP. You can see if UDP packets are refused, but if they aren't refused it could be either because they were accepted, or because a firewall blocked them.
On the other hand, if you're checking to see whether your service is listening, why wouldn't you just build a test function into it that would respond to a status query?