check_port.py 313 B

12345678910111213
  1. #!/usr/bin/env python
  2. import sys,os,socket
  3. def IsOpen(ip,port):
  4. socket.setdefaulttimeout(5)
  5. s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  6. try:
  7. s.connect((ip,int(port)))
  8. s.shutdown(2)
  9. print(True)
  10. except:
  11. print(False)
  12. if __name__ == '__main__':
  13. IsOpen(sys.argv[1],int(sys.argv[2]))