1#!/usr/bin/env python3 2# Copyright 2015 gRPC authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15"""Opens a TCP connection to a specified server and then exits.""" 16 17import argparse 18import socket 19import sys 20import threading 21import time 22 23 24def main(): 25 argp = argparse.ArgumentParser( 26 description="Open a TCP handshake to a server" 27 ) 28 argp.add_argument( 29 "-s", 30 "--server_host", 31 default=None, 32 type=str, 33 help="Server host name or IP.", 34 ) 35 argp.add_argument( 36 "-p", 37 "--server_port", 38 default=0, 39 type=int, 40 help="Port that the server is listening on.", 41 ) 42 argp.add_argument( 43 "-t", 44 "--timeout", 45 default=1, 46 type=int, 47 help="Force process exit after this number of seconds.", 48 ) 49 args = argp.parse_args() 50 socket.create_connection( 51 [args.server_host, args.server_port], timeout=args.timeout 52 ) 53 54 55if __name__ == "__main__": 56 main() 57