搜索
首页运维linux运维Linux nc命令如何使用

Linux nc命令如何使用

May 17, 2023 pm 05:13 PM
linux

一、命令简介

Netcat的简称nc,是一款被誉为网络界瑞士军刀的强大网络工具。实际上,Linux系统中的命令是ncat。nc命令只是一个指向ncat的软链接。nc命令的主要作用如下:

实现任意TCP/UDP端口的侦听,nc可以作为server以TCP或UDP方式侦听指定端口端口的扫描,nc可以作为client发起TCP或UDP连接机器之间传输文件机器之间网络测速

nc如果找不到nc命令可以使用yum install -y nc安装,其中centos6系统安装的是nc-1.84-24.el6.x86_64,centos7安装的是nmap-ncat-6.40-19.el7.x86_64。

二、使用示例

1、验证服务器端口是否通

如下验证172.16.7.78服务器的80端口通,81端口不通。

Linux nc命令如何使用

2、拷贝文件

首先在文件接收终端test2机器上激活nc监听

Linux nc命令如何使用

然后在文件发送终端test1机器上发送文件

Linux nc命令如何使用

在test2上检查文件是否已成功接收

Linux nc命令如何使用

3、终端之间通信聊天

test1主机上启动nc监听,ctrl+C中断通信。

Linux nc命令如何使用

test2上连接监听,ctrl+C中断通信。

Linux nc命令如何使用

4、端口扫描

端口扫描,通的端口返回succeeded,不通的端口返回refused。此扫描基于nc-1.84-24.el6.x86_64。
[root@test1 /]# nc -v -w 1 172.16.7.78 -z 22-81
Connection to 172.16.7.78 22 port [tcp/ssh] succeeded!
nc: connect to 172.16.7.78 port 23 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 24 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 25 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 26 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 27 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 28 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 29 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 30 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 31 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 32 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 33 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 34 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 35 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 36 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 37 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 38 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 39 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 40 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 41 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 42 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 43 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 44 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 45 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 46 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 47 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 48 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 49 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 50 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 51 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 52 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 53 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 54 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 55 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 56 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 57 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 58 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 59 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 60 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 61 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 62 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 63 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 64 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 65 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 66 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 67 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 68 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 69 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 70 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 71 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 72 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 73 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 74 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 75 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 76 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 77 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 78 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 79 (tcp) failed: Connection refused
Connection to 172.16.7.78 80 port [tcp/http] succeeded!
nc: connect to 172.16.7.78 port 81 (tcp) failed: Connection refused

5、验证UDP端口

[root@test1 ~]# nc -uvz 192.168.0.125 111
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.0.125:111.
Ncat: UDP packet sent successfully
Ncat: 1 bytes sent, 0 bytes received in 2.04 seconds.

6、测速网速

测速网速需要结合dstat命令查看。

安装dstat命令

[root@test1 ~]# yum install -y dstat
[root@test2 ~]# yum install -y dstat

test1主机上监听端口

[root@test1 ~]# nc -l 33333 >/dev/null

test2主机上发送数据,全0数据

[root@test2 ~]# nc 192.168.0.124 33333

查看流量

[root@test1 ~]# dstat
[root@test2 ~]# dstat

Linux nc命令如何使用

Linux nc命令如何使用

三、使用语法及参数说明

1、使用语法

用法:ncat [options] [hostname] [port]

2、参数说明

以上是Linux nc命令如何使用的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:亿速云。如有侵权,请联系admin@php.cn删除
Linux操作:管理文件,目录和权限Linux操作:管理文件,目录和权限Apr 23, 2025 am 12:19 AM

在Linux中,文件和目录管理使用ls、cd、mkdir、rm、cp、mv命令,权限管理使用chmod、chown、chgrp命令。1.文件和目录管理命令如ls-l列出详细信息,mkdir-p递归创建目录。2.权限管理命令如chmod755file设置文件权限,chownuserfile改变文件所有者,chgrpgroupfile改变文件所属组。这些命令基于文件系统结构和用户、组系统,通过系统调用和元数据实现操作和控制。

Linux中的维护模式是什么?解释了Linux中的维护模式是什么?解释了Apr 22, 2025 am 12:06 AM

MaintenancemodeInuxisAspecialBootenvironmentforforcalsystemmaintenancetasks.itallowsadMinistratorStoperFormTaskSlikerSettingPassingPassingPasswords,RepairingFilesystems,andRecoveringFrombootFailuresFailuresFailuresInamInimAlenimalenimalenrenmentrent.ToEnterMainterMainterMaintErmaintErmaintEncemememodeBoode,Interlecttheboo

Linux:深入研究其基本部分Linux:深入研究其基本部分Apr 21, 2025 am 12:03 AM

Linux的核心组件包括内核、文件系统、Shell、用户空间与内核空间、设备驱动程序以及性能优化和最佳实践。1)内核是系统的核心,管理硬件、内存和进程。2)文件系统组织数据,支持多种类型如ext4、Btrfs和XFS。3)Shell是用户与系统交互的命令中心,支持脚本编写。4)用户空间与内核空间分离,确保系统稳定性。5)设备驱动程序连接硬件与操作系统。6)性能优化包括调整系统配置和遵循最佳实践。

Linux体系结构:揭示5个基本组件Linux体系结构:揭示5个基本组件Apr 20, 2025 am 12:04 AM

Linux系统的五个基本组件是:1.内核,2.系统库,3.系统实用程序,4.图形用户界面,5.应用程序。内核管理硬件资源,系统库提供预编译函数,系统实用程序用于系统管理,GUI提供可视化交互,应用程序利用这些组件实现功能。

Linux操作:利用维护模式Linux操作:利用维护模式Apr 19, 2025 am 12:08 AM

Linux的维护模式可以通过GRUB菜单进入,具体步骤为:1)在GRUB菜单中选择内核并按'e'编辑,2)在'linux'行末添加'single'或'1',3)按Ctrl X启动。维护模式提供了一个安全环境,适用于系统修复、重置密码和系统升级等任务。

Linux:如何进入恢复模式(和维护)Linux:如何进入恢复模式(和维护)Apr 18, 2025 am 12:05 AM

进入Linux恢复模式的步骤是:1.重启系统并按特定键进入GRUB菜单;2.选择带有(recoverymode)的选项;3.在恢复模式菜单中选择操作,如fsck或root。恢复模式允许你以单用户模式启动系统,进行文件系统检查和修复、编辑配置文件等操作,帮助解决系统问题。

Linux的基本要素:为初学者解释Linux的基本要素:为初学者解释Apr 17, 2025 am 12:08 AM

Linux的核心组件包括内核、文件系统、Shell和常用工具。1.内核管理硬件资源并提供基本服务。2.文件系统组织和存储数据。3.Shell是用户与系统交互的接口。4.常用工具帮助完成日常任务。

Linux:看看其基本结构Linux:看看其基本结构Apr 16, 2025 am 12:01 AM

Linux的基本结构包括内核、文件系统和Shell。1)内核管理硬件资源,使用uname-r查看版本。2)EXT4文件系统支持大文件和日志,使用mkfs.ext4创建。3)Shell如Bash提供命令行交互,使用ls-l列出文件。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

参数参数说明
-4Use IPv4 only
-6Use IPv6 only
-U, --unixsock仅使用Unix域套接字
-C, --crlf将crlf用于EOL序列
-c, --sh-exec

通过/bin/sh执行给定的命令
-e, --exec 执行给定的命令
–lua-exec 执行给定的lua脚本
-g hop1[,hop2,…] 松散源路由跃点(最多8个)
-G 松散源路由跃点指针(4,8,12,…)
-m, --max-conns 最大同时连接数
-h, --help 帮助显示此帮助屏幕
-d, --delay 读/写之间的延迟
-o, --output 将会话数据转储到文件
-x, --hex-dump 将会话数据作为十六进制转储到文件
-i, --idle-timeout 空闲读/写超时
-p, --source-port port 指定要使用的源端口
-s, --source addr 指定要使用的源地址(不影响-l)
-l, --listen 绑定并侦听传入连接
-k, --keep-open 在侦听模式下接受多个连接
-n, --nodns 不通过DNS解析主机名
-t, --telnet 应答telnet协商
-u, --udp 使用udp而不是默认TCP
–sctp 使用sctp而不是默认的TCP
-v, --verbose 设置详细级别(可以多次使用)
-w, --wait 连接超时时间,单位秒
-z 仅报告连接状态
–append-output 追加而不是重击指定的输出文件
–send-only 忽略接收;退出EOF
–recv-only 从不发送任何东西
–allow 给定主机连接到Ncat
–allowfile 允许连接到Ncat的主机的文件
–deny 给定主机连接到Ncat
–denyfile 拒绝连接到Ncat的主机文件
–broker 启用Ncat的连接代理模式
–chat 开始一个简单的Ncat聊天服务器
–proxy 指定要通过代理的主机地址
–proxy-type 指定代理类型(“http”或“socks4”或“socks5”)
–proxy-auth 通过HTTP或SOCKS代理服务器进行身份验证
–ssl 使用ssl连接或侦听
–ssl-cert 指定用于侦听的ssl证书文件(PEM)
–ssl-key 指定用于侦听的ssl私钥(PEM)
–ssl-verify 证书的信任和域名
–ssl-trustfile 包含可信ssl证书的PEM文件
–ssl-ciphers Cipherlist包含要使用的ssl密码
–version 查看命令版本