Linux开启指定端口测试

  1. 操作系统的版本为centos7.5

    linux开启指定端口方法
  2. 使用系统自带的python版本

    linux开启指定端口方法
  3. 编写duankou.py

    import socket
    
    ip_port = ('192.168.122.136',9999)
    sk = socket.socket()
    sk.bind(ip_port)
    sk.listen(5)
    while True:
        print ('server waiting...')
        conn,addr = sk.accept()
        client_data = conn.recv(1024)
        print (str(client_data,'utf8'))
        conn.sendall(bytes('abc','utf8'))
        conn.close()

    linux开启指定端口方法

  4. 直接运行

    python duankou.py 

    linux开启指定端口方法
  5. 验证端口的存活性

    netstat -tnlp|grep 9999

    linux开启指定端口方法
  6. 也可以在其它机器上进行端口连通性测试
    linux开启指定端口方法
posted @ 2021-09-14 16:24  民宿  阅读(309)  评论(0)    收藏  举报