#!/usr/bin/env python
#coding: utf-8

import sys
import socket


if __name__ == '__main__':
    if len(sys.argv) < 3:
        sys.exit(2)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(1)
    # if port is not alive, `socket.error` will be raised and exit with 1
    s.connect((sys.argv[1], int(sys.argv[2])))
    if s.send('\n'.encode()) != 1:
        raise Exception("failed to send")
