title: its always showing port closed even when have a listener setup and its going the listener
body: <p>So I used the socket connect_ex which means in the if statement if the result will be true the port is closed because it's true when it gets an error but if it's false the port is open but it's not working.
      #!/usr/bin/python</p>
  
  <pre><code>import socket 
  
  ip = raw_input("Enter the IP address:   ")
  
  port =input("Enter The Port Number:  ")
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  if sock.connect_ex((ip,port)):
  
     print"Port" , port, "is closed"  
  
  else:
  
     print "Port", port, "is closed" 
  </code></pre>