Port checker

This was useful when we testing a migration between database servers.

import socket
import sys

for i in range(1,5):
  try:
    HOST = "foo" + str(i)
    PORT = 2484
    print HOST + " " + str(PORT)
    sock = socket.socket()
    sock.connect((HOST, int(PORT)))
    print "got socket"
    PORT = "640" + str(i)
    print HOST + " " + str(PORT)
    sock = socket.socket()
    sock.connect((HOST, int(PORT)))
    print "got socket"
  except:
    print sys.exc_info()[1]

It should yield something similar to what is below…

C:\>mysock.py
foo1 2484
got socket
foo1 6401
got socket
foo2 2484
got socket
foo2 6402
got socket
foo3 2484
got socket
foo3 6403
got socket
foo4 2484
got socket
foo4 6404
got socket

C:\>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.