IP banning in-game

Is there a way to IP ban people in a game I make? The current strip of code I have for this is this http://gyazo.com/9ab9be44e8063671c8def90faecbb71d

But al that does is kick the user from the game server and they can still connect. Is there a way I can ban there IP so theyre unable to access the server?

You will need to add logic to where your game initially starts a new incoming network connection. If the ip is in the ban list then you can return a response with a message that the ip is banned, the drop the connection.