netcat tldr

Mac OS 推荐用 brew install netcat 装 GNU netcat,更为原生Linux体验
之后 vim ~/.zshrc
alias nc=‘netcat’
. ~/.zshrc
➜ ~ tldr nc
nc
Netcat is a versatile utility for working with TCP or UDP data.

  • 监听端口 Listen on a specified port and print any data received:

    nc -l port
    例如 nc -l 11111 终端开着
    然后开另一个终端 telnet localhost 11111
    往里面输入,第一个终端就看得到了
    同样第一个终端也可以输入,第二个终端能看到,双向的

  • 连端口 Connect to a certain port (you can then write to this port):

    nc ip_address port
    类似 telent,不过telent 所有 Linux都会装,但是netcat不一定 。此外MacOS之后的版本telent也不会装。

  • 设置超时时间 Set a timeout:

    nc -w timeout_in_seconds ipaddress port
    这个事一旦连接成功了,那么多时间不回话就会关掉

  • 存文件 Serve a file:

    nc -l port < file
    开了之后,连接成功了才会传送

  • Receive a file:

    nc ip_address port > file
    和上面一个连起来用

  • Server stay up after client detach:

    nc -k -l port
    这个再结合 man 看一下

 -k      Forces nc to stay listening for another connection after its cur-
            rent connection is completed.  It is an error to use this option
        without the -l option.

就是之前的一个 listen 了,另一个连上了,连上的那个断开了,第一个也结束了。但是加上了 -k,第二个关了,第一个还在

  • Client stay up after EOF:

    nc -q timeout ip_address
    没看到这个命令

  • Scan the open ports of a specified host:

    nc -v -z ip_address port
    man 一下

 -v
  --verbose
      Prints status messages, usually needed for using netcat as user
      front-end.  All messages are printed to stderr in order not to
      affect the data stream.

-v 都是详细信息

   --zero
      Sets the zero I/O flag for the selected mode.  In connect mode it
      means that as soon as the port is open it is immediately shutdown
      and closed.  This may be useful for probing or scanning (even if
      there are faster portscanners out there, but this may be useful for
     scripting purposes).  In listen mode, it makes netcat refusing all
      the incoming connections thus running in timeout (if set), or wait-
      ing forever.  In both cases, no data is transfered.
      This option is incompatible with the tunnel mode.

设置一个 0 IO的标志,不同模式下有不同的用法

  • 连接模式 连上了立刻关了,可以用来扫端口

  • 监听模式 拒绝所有连接

  • tunnel 模式不兼容

  • Act as proxy and forward data from a local TCP port to the given remote host:

    nc -l local_port | nc hostname remote_port
    当代理
    监听一个端口,再发给别人

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值