netstat -plant | awk '{print $4}' | grep %s:%s | wc -l
You can use Python to do the splitting, grepping and counting:
process = subprocess.Popen(['netstat', '-plant'], stdout=subprocess.PIPE)
num_matches = 0
host_and_port = "%s:%s" % (ip, port)
for line in process.stdout:
parts = line.split()
if parts[3] == host_and_port: # or host_and_port in parts[3]
num_matches += 1
print num_matches