def is_valid_port(entry, allow_zero=False):
 try:
  value = int(entry)
  if (str(value) != str(entry)):
   return False
  elif (allow_zero and (value == 0)):
   return True
  else:
   return ((value > 0) and (value < 65536))
 except TypeError:
  if isinstance(entry, (tuple, list)):
   for port in entry:
    if (not is_valid_port(port, allow_zero)):
     return False
   return True
  else:
   return False
 except ValueError:
  return False

def is_valid_port ( entry , allow_zero = False ) : try : value = int ( entry ) if ( str ( value ) != str ( entry ) ) : return False elif ( allow_zero and ( value == 0 ) ) : return True else : return ( ( value > 0 ) and ( value < 65536 ) ) except TypeError : if isinstance ( entry , ( tuple , list ) ) : for port in entry : if ( not is_valid_port ( port , allow_zero ) ) : return False return True else : return False except ValueError : return False
check if given port is valid .