def is_port_free(port, address):
 try:
  s = socket.socket()
  if (address == 'localhost'):
   s.bind(('localhost', port))
   free = True
  else:
   s.connect((address, port))
   free = False
 except socket.error:
  if (address == 'localhost'):
   free = False
  else:
   free = True
 s.close()
 return free

def is_port_free ( port , address ) : try : s = socket . socket ( ) if ( address == 'localhost' ) : s . bind ( ( 'localhost' , port ) ) free = True else : s . connect ( ( address , port ) ) free = False except socket . error : if ( address == 'localhost' ) : free = False else : free = True s . close ( ) return free
return true if the given port is available for use .