nc命令说明

nc

nc(netcat)是一种用于在网络上传输数据的命令行工具,支持TCP、UDP、Unix域套接字和其他协议。它可以用于创建客户端和服务器,也可以用于在不同主机之间传输文件、扫描端口、进行端口转发等。

以下是一些nc命令的常见用法:

  1. 创建TCP或UDP连接:
nc host port

例如,要连接到远程主机example.com的80端口(HTTP),可以使用以下命令:

nc example.com 80
  1. 创建监听TCP或UDP连接:
nc -l -p port

例如,要在本地主机的8080端口上监听HTTP请求,可以使用以下命令:

nc -l -p 8080
  1. 文件传输:

从本地主机向远程主机发送文件:

nc host port < file

从远程主机向本地主机接收文件:

nc -l -p port > file
  1. 端口扫描:
nc -zv host port

例如,要扫描远程主机example.com的80端口是否开放,可以使用以下命令:

nc -zv example.com 80
  1. 端口转发:
nc -l -p local_port -c 'nc remote_host remote_port'

例如,要将本地主机的8080端口上的HTTP请求转发到远程主机example.com的80端口,可以使用以下命令:

nc -l -p 8080 -c 'nc example.com 80'

这只是nc命令的一些常见用法,该命令还可以用于许多其他用途,具体取决于您的需求。

nc -v host port

当使用 “nc -v host port” 命令连接到指定的主机和端口时,命令的返回结果将提供以下信息:

  • 如果连接成功,则命令将显示 “Connection to host port [tcp/*] succeeded!” 的消息,其中 host 和 port 是指定的主机和端口号。这表示连接已成功建立。

  • 如果连接失败,则命令将显示 “nc: connect to host port [tcp/*] failed: Connection refused” 或类似的错误消息,其中 host 和 port 是指定的主机和端口号。这表示连接尝试失败,可能是由于主机或端口不可用或防火墙阻止了连接。

  • 如果命令没有连接到指定的主机和端口,则命令将保持运行状态,直到手动中断或超时。在这种情况下,命令没有返回结果,但可以通过 Ctrl+C 中断命令。

  • 如果指定了多个 “-v” 选项,则命令将显示更详细的信息,例如连接状态、数据传输速率和其他相关详细信息。

nc -h

nc -h
Ncat 7.50 ( https://nmap.org/ncat )
Usage: ncat [options] [hostname] [port]

Options taking a time assume seconds. Append 'ms' for milliseconds,
's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).
  -4                         Use IPv4 only
  -6                         Use IPv6 only
  -U, --unixsock             Use Unix domain sockets only
  -C, --crlf                 Use CRLF for EOL sequence
  -c, --sh-exec <command>    Executes the given command via /bin/sh
  -e, --exec <command>       Executes the given command
      --lua-exec <filename>  Executes the given Lua script
  -g hop1[,hop2,...]         Loose source routing hop points (8 max)
  -G <n>                     Loose source routing hop pointer (4, 8, 12, ...)
  -m, --max-conns <n>        Maximum <n> simultaneous connections
  -h, --help                 Display this help screen
  -d, --delay <time>         Wait between read/writes
  -o, --output <filename>    Dump session data to a file
  -x, --hex-dump <filename>  Dump session data as hex to a file
  -i, --idle-timeout <time>  Idle read/write timeout
  -p, --source-port port     Specify source port to use
  -s, --source addr          Specify source address to use (doesn't affect -l)
  -l, --listen               Bind and listen for incoming connections
  -k, --keep-open            Accept multiple connections in listen mode
  -n, --nodns                Do not resolve hostnames via DNS
  -t, --telnet               Answer Telnet negotiations
  -u, --udp                  Use UDP instead of default TCP
      --sctp                 Use SCTP instead of default TCP
  -v, --verbose              Set verbosity level (can be used several times)
  -w, --wait <time>          Connect timeout
  -z                         Zero-I/O mode, report connection status only
      --append-output        Append rather than clobber specified output files
      --send-only            Only send data, ignoring received; quit on EOF
      --recv-only            Only receive data, never send anything
      --allow                Allow only given hosts to connect to Ncat
      --allowfile            A file of hosts allowed to connect to Ncat
      --deny                 Deny given hosts from connecting to Ncat
      --denyfile             A file of hosts denied from connecting to Ncat
      --broker               Enable Ncat's connection brokering mode
      --chat                 Start a simple Ncat chat server
      --proxy <addr[:port]>  Specify address of host to proxy through
      --proxy-type <type>    Specify proxy type ("http" or "socks4" or "socks5")
      --proxy-auth <auth>    Authenticate with HTTP or SOCKS proxy server
      --ssl                  Connect or listen with SSL
      --ssl-cert             Specify SSL certificate file (PEM) for listening
      --ssl-key              Specify SSL private key (PEM) for listening
      --ssl-verify           Verify trust and domain name of certificates
      --ssl-trustfile        PEM file containing trusted SSL certificates
      --ssl-ciphers          Cipherlist containing SSL ciphers to use
      --version              Display Ncat's version information and exit

See the ncat(1) manpage for full options, descriptions and usage examples
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值