Pass in a port number and, if open, it will be immediately closed.

#!/bin/bash

echo -en "\nKilling $1\n"

kill $(lsof -i :$1 | grep IPv4 | awk -F ' ' '{print $2}') &> /dev/null

echo -en "\nNetstat for $1: \n";

netstat -a | grep $1 | grep -v grep | grep -v tcp6

echo -en "\nPID for program holding port $1 Killed.\n\n"