美文网首页
mac 查看端口占用情况

mac 查看端口占用情况

作者: Sunnky | 来源:发表于2019-04-18 21:55 被阅读0次

    linux中,很容易的可以用netstat -tnlp查看出端口的占用情况,但该命令在mac上被大大简化,比如-p命令不支持:

    $ netstat -tnlp | grep 8000
    netstat: option requires an argument -- p
    Usage:  netstat [-AaLlnW] [-f address_family | -p protocol]
        netstat [-gilns] [-f address_family]
        netstat -i | -I interface [-w wait] [-abdgRtS]
        netstat -s [-s] [-f address_family | -p protocol] [-w wait]
        netstat -i | -I interface -s [-f address_family | -p protocol]
        netstat -m [-m]
        netstat -r [-Aaln] [-f address_family]
        netstat -rs [-s]
    

    但如果只用netstat -tnl | grep 8000则查不出任何东西,显然是不对的

    image.png
    此时可以用:netstat -anv | grep 8000
    $ netstat -anv | grep 8000
    tcp4       0      0  127.0.0.1.8000         *.*                    LISTEN      131072 131072  62410      0 0x0000 0x00000006
    tcp46      0      0  *.8000                 *.*                    LISTEN      131072 131072  38336      0 0x0100 0x00000026
    

    可以看到,pid以及被哪个进程占用还是不知道,这时只能用lsof命令了:

    $ lsof -i:8000
    COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    main    38336  mac    6u  IPv6 0x8736b0dd601c8911      0t0  TCP *:irdmi (LISTEN)
    Python  62410  mac   23u  IPv4 0x8736b0dd4e023851      0t0  TCP localhost:irdmi (LISTEN)
    

    相关文章

      网友评论

          本文标题:mac 查看端口占用情况

          本文链接:https://www.haomeiwen.com/subject/hwpxgqtx.html