当前位置: 首页 > news >正文

Linux网络瑞士军刀 nc(netcat)

1.命令简介

nc(netcat)是一个短小精悍、功能实用、简单可靠的网络工具,主要有如下作用:

(1)端口侦听,nc 可以作为 server 以 TCP 或 UDP 方式侦听指定端口;

(2)端口扫描,nc 可以作为 client 发起 TCP 或 UDP 请求;

(3)机器之间传输文件;

(4)机器之间网络测速。

2.命令格式

nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port] [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [hostname] [port[s]]

常用选项:

  • -4:只使用 IPv4 地址
  • -6:只使用 IPv6 地址
  • -l:启动本地监听
  • -n:不使用 DNS 解析
  • -p:指定源端口
  • -s:指定源 IP 地址
  • -u:使用 UDP,默认是 TCP
  • -v:显示详细信息
  • -w:设定超时时间(只适合用在 Client 端)
  • -d:禁止从标准输入读取数据,也就是客户端输入数据不会发送到服务端
  • -k:让服务端保持连接,不断开

3.常用示例

模拟服务端

nc -vkl 8080

模拟客户端

nc -v 127.0.0.1 8888

连接日志

#server
root@VM-16-3-ubuntu:~# nc -vkl 8080
Listening on 0.0.0.0 8080
Connection received on localhost 42930#client
root@VM-16-3-ubuntu:~# nc -v 127.0.0.1 8080
Connection to 127.0.0.1 8080 port [tcp/http-alt] succeeded!
#随后双方便可输入消息发送

发送文件

nc 不仅可以发送消息,还可发送文件。

假设服务端有一个 out.txt 的空文件,而客户端有一个 in.txt 文件,含有数据:hello server

Server 端接收文件:

nc localhost 6000 > out.txt

Client 端发送文件:

nc localhost 6000 < in.txt

之后,我们可以看到 Server 端的 out.txt 文件中已经有数据了:

# cat out.txt
hello server

除了可以发送文件,nc 也可以发送目录,只需要将目录压缩发送即可。

端口扫码

端口扫描是一个非常重要的功能,很多时候系统管理员会通过扫描服务器上端口,来识别系统中漏洞,nc 工具提供了非常方便的操作:

nc -vz 127.0.0.1 1-100

这条命令扫描 192.168.1.3 上 1-100 端口区间,有哪些端口是开放的。

# nc -vz 127.0.0.1 1-100
nc: connect to 127.0.0.1 port 1 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 2 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 3 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 4 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 5 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 6 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 7 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 8 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 9 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 10 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 11 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 12 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 13 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 14 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 15 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 16 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 17 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 18 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 19 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 20 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 21 (tcp) failed: Connection refused
Connection to 127.0.0.1 22 port [tcp/ssh] succeeded!
nc: connect to 127.0.0.1 port 23 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 24 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 25 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 26 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 27 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 28 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 29 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 30 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 31 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 32 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 33 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 34 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 35 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 36 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 37 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 38 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 39 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 40 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 41 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 42 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 43 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 44 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 45 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 46 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 47 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 48 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 49 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 50 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 51 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 52 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 53 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 54 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 55 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 56 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 57 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 58 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 59 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 60 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 61 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 62 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 63 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 64 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 65 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 66 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 67 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 68 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 69 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 70 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 71 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 72 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 73 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 74 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 75 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 76 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 77 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 78 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 79 (tcp) failed: Connection refused
Connection to 127.0.0.1 80 port [tcp/http] succeeded!
nc: connect to 127.0.0.1 port 81 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 82 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 83 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 84 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 85 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 86 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 87 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 88 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 89 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 90 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 91 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 92 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 93 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 94 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 95 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 96 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 97 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 98 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 99 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 100 (tcp) failed: Connection refused

可以看到,只有 22和80号端口是开放的。

总结

nc 通过在两台机器之间建立连接来完成很多网络功能,数据传输、网络连接、端口扫描等,也有助于我们进行网络调试,排查网络故障。

相关文章:

Linux网络瑞士军刀 nc(netcat)

1.命令简介 nc&#xff08;netcat&#xff09;是一个短小精悍、功能实用、简单可靠的网络工具&#xff0c;主要有如下作用&#xff1a; &#xff08;1&#xff09;端口侦听&#xff0c;nc 可以作为 server 以 TCP 或 UDP 方式侦听指定端口&#xff1b; &#xff08;2&#x…...

1.Spring入门

1.1 Spring简介 Spring是一个轻量级Java 企业级应用程序开发框架&#xff0c;目的是为了解决企业级应用开发的业务逻辑层和其他各层的耦合问题。它是一个分层的JavaSE/EEfull-stack(一站式) 轻量级开源框架&#xff0c;为开发Java应用程序提供全面的基础架构支持。 Spring Fra…...

【JavaEE Spring 项目】消息队列的设计

消息队列的设计 一、消息队列的背景知识二、需求分析核心概念⼀个⽣产者, ⼀个消费者N 个⽣产者, N 个消费者Broker Server 中的相关概念核⼼ API交换机类型 (Exchange Type)持久化⽹络通信消息应答 三、 模块划分四、 项⽬创建五、创建核心类创建 Exchange创建 MSGQUeue创建 B…...

SpringFramework学习笔记(Spring IoC,aop,tx)

SpringFramework 本篇笔记是基于尚硅谷学习资料的整理&#xff0c;涉及到其笔记的简化&#xff0c;补充&#xff0c;以及我在学习中遇到的与无法理解的问题及解决&#xff0c;如果想看完整及后续的笔记&#xff0c;可以去https://www.wolai.com/v5Kuct5ZtPeVBk4NBUGBWF查看官方…...

口腔管理平台 |基于springboot框架+ Mysql+Java+B/S结构的口腔管理平台 设计与实现(可运行源码+数据库+lw文档)

推荐阅读100套最新项目 最新ssmjava项目文档视频演示可运行源码分享 最新jspjava项目文档视频演示可运行源码分享 最新Spring Boot项目文档视频演示可运行源码分享 目录 前台功能效果图 管理员功能登录前台功能效果图 会员功能 系统功能设计 数据库E-R图设计 lunwen参考…...

【设计模式】Java 设计模式之工厂模式(Factory Pattern)

工厂模式&#xff08;Factory Pattern&#xff09;深入解析 一、工厂模式概述 工厂模式是一种创建型设计模式&#xff0c;它提供了一种封装对象创建过程的方式&#xff0c;将对象的创建与使用分离。工厂模式的核心思想是将“实例化对象”的操作与“使用对象”的操作分开&…...

安卓UI面试题 36-40

36. 简述 getDimension、getDimensionPixelOffset 和 getDimensionPixelSize 三者的区别? 相同点 单位为dp/sp时,都会乘以density,单位为px则不乘不同点 1、getDimension返回的是float值 2、getDimensionPixelSize,返回的是int值,float转成int时,四舍五入 3、getDimensio…...

Java有哪些常用的集合?

1、典型回答 在 Java 中&#xff0c;常用的集合有以下几个&#xff1a; 列表(List)&#xff1a;有序集合&#xff0c;可以包含重复元素。常见实现类有 ArrayList、LinkedList、 Vector 等集合(Set)&#xff1a;无序集合&#xff0c;不允许包含重复元素。常见实现类有 HashSet、…...

虚拟机网络链接

在虚拟网络设置中找到如下界面&#xff1a; "子网 IP" 192.168.79.0/24 表示一个局域网络&#xff0c;它有254个可能的IP地址可供分配&#xff08;192.168.79.1到192.168.79.254&#xff09;&#xff0c;255.255.255.0 是子网掩码&#xff0c;定义了网络和主机部分。…...

代码随想录阅读笔记-字符串【反转字符串】

题目 编写一个函数&#xff0c;其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。 不要给另外的数组分配额外的空间&#xff0c;你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。 你可以假设数组中的所有字符都是 ASCII 码表中的可打印…...

4. Linux文件属性和目录系列

在 Linux 系统中,文件和目录是基本的文件系统组成部分。文件系统是用于组织和存储文件的一种结构,而文件和目录则是文件系统的核心元素。以下是对 Linux 文件和目录的详细解释: 1. 文件(File) 在 Linux 中,文件是数据的集合,可以是文本文件、二进制文件、设备文件等。…...

Linux第78步_使用原子整型操作来实现“互斥访问”共享资源

使用原子操作来实现“互斥访问”LED灯设备&#xff0c;目的是每次只允许一个应用程序使用LED灯。 1、创建MyAtomicLED目录 输入“cd /home/zgq/linux/Linux_Drivers/回车” 切换到“/home/zgq/linux/Linux_Drivers/”目录 输入“mkdir MyAtomicLED回车”&#xff0c;创建MyA…...

C++——C++11(3)

C——C11&#xff08;3&#xff09; lambda表达式&#xff08;匿名的仿函数对象&#xff09;一些注意点lambda捕捉列表[][&][this] lambda的赋值 function包装器function成员函数的包装 bind绑定参数 我们今天接着来了解一下C11一些新的特性&#xff0c;如果还没有看过上两…...

更改el-tabs默认样式,实现tab标签居中显示,标签对应内容使用另一个div显示

首先看效果图 如图所示&#xff0c;标签在浏览器窗口居中&#xff0c;但是下面的内容依然是默认从左到右&#xff0c;不会受到tab样式的影响 <template><div><div style"display: flex; justify-content: center; align-items: center;"><el-…...

微信小程序原生<map>地图实现标记多个位置以及map 组件 callout 自定义气泡

一、老规矩先上效果图: 二、在pages文件夹下新建image文件夹用来存放标记的图片。 三、代码片段 也可以参考小程序文档:https://developers.weixin.qq.com/miniprogram/dev/component/map.html index.wxml代码 <mapid="map"style="width: 100%; height:1…...

外包干了3天,技术明显进步。。。。。

先说一下自己的情况&#xff0c;本科生&#xff0c;19年通过校招进入南京某软件公司&#xff0c;干了接近2年的功能测试&#xff0c;今年年初&#xff0c;感觉自己不能够在这样下去了&#xff0c;长时间呆在一个舒适的环境会让一个人堕落!而我已经在一个企业干了2年的功能测试&…...

Transformer学习笔记(二)

一、文本嵌入层Embedding 1、作用&#xff1a; 无论是源文本嵌入还是目标文本嵌入&#xff0c;都是为了将文本中词汇的数字表示转变为向量表示&#xff0c;希望在这样的高维空间捕捉词汇间的关系。 二、位置编码器Positional Encoding 1、作用&#xff1a; 因为在Transformer…...

C#求水仙花数

目录 1.何谓水仙花数 2.求三位数的水仙花数 3.在遍历中使用Math.DivRem方法再求水仙花数 1.何谓水仙花数 水仙花数&#xff08;Narcissistic number&#xff09;是指一个 n 位正整数&#xff0c;它的每个位上的数字的 n 次幂之和等于它本身。例如&#xff0c;153 是一个 3 …...

FFmpeg转码参数说明及视频转码示例

-b : 设置音频或者视频的转码码率 -b:v 只设置视频码率 -b:a 只设置音频码率 -ab: 只设置音频码率, 默认码率大小为: 128k bit/s -g: 设置视频GOP大小,表示I帧之间的间隔,默认为12 -ar: 设置音频采样率,默认0 -ac: 设置音频通道数量 默认0 -bf: 设置连…...

qiankun:vite/webpack项目配置

相关博文&#xff1a; https://juejin.cn/post/7216536069285429285?searchId202403091501088BACFF113F980BA3B5F3 https://www.bilibili.com/video/BV12T411q7dq/?spm_id_from333.337.search-card.all.click qiankun结构&#xff1a; 主应用base&#xff1a;vue3historyv…...

<6>-MySQL表的增删查改

目录 一&#xff0c;create&#xff08;创建表&#xff09; 二&#xff0c;retrieve&#xff08;查询表&#xff09; 1&#xff0c;select列 2&#xff0c;where条件 三&#xff0c;update&#xff08;更新表&#xff09; 四&#xff0c;delete&#xff08;删除表&#xf…...

树莓派超全系列教程文档--(61)树莓派摄像头高级使用方法

树莓派摄像头高级使用方法 配置通过调谐文件来调整相机行为 使用多个摄像头安装 libcam 和 rpicam-apps依赖关系开发包 文章来源&#xff1a; http://raspberry.dns8844.cn/documentation 原文网址 配置 大多数用例自动工作&#xff0c;无需更改相机配置。但是&#xff0c;一…...

基于ASP.NET+ SQL Server实现(Web)医院信息管理系统

医院信息管理系统 1. 课程设计内容 在 visual studio 2017 平台上&#xff0c;开发一个“医院信息管理系统”Web 程序。 2. 课程设计目的 综合运用 c#.net 知识&#xff0c;在 vs 2017 平台上&#xff0c;进行 ASP.NET 应用程序和简易网站的开发&#xff1b;初步熟悉开发一…...

【算法训练营Day07】字符串part1

文章目录 反转字符串反转字符串II替换数字 反转字符串 题目链接&#xff1a;344. 反转字符串 双指针法&#xff0c;两个指针的元素直接调转即可 class Solution {public void reverseString(char[] s) {int head 0;int end s.length - 1;while(head < end) {char temp …...

Spring Boot+Neo4j知识图谱实战:3步搭建智能关系网络!

一、引言 在数据驱动的背景下&#xff0c;知识图谱凭借其高效的信息组织能力&#xff0c;正逐步成为各行业应用的关键技术。本文聚焦 Spring Boot与Neo4j图数据库的技术结合&#xff0c;探讨知识图谱开发的实现细节&#xff0c;帮助读者掌握该技术栈在实际项目中的落地方法。 …...

全志A40i android7.1 调试信息打印串口由uart0改为uart3

一&#xff0c;概述 1. 目的 将调试信息打印串口由uart0改为uart3。 2. 版本信息 Uboot版本&#xff1a;2014.07&#xff1b; Kernel版本&#xff1a;Linux-3.10&#xff1b; 二&#xff0c;Uboot 1. sys_config.fex改动 使能uart3(TX:PH00 RX:PH01)&#xff0c;并让boo…...

Spring数据访问模块设计

前面我们已经完成了IoC和web模块的设计&#xff0c;聪明的码友立马就知道了&#xff0c;该到数据访问模块了&#xff0c;要不就这俩玩个6啊&#xff0c;查库势在必行&#xff0c;至此&#xff0c;它来了。 一、核心设计理念 1、痛点在哪 应用离不开数据&#xff08;数据库、No…...

学习STC51单片机32(芯片为STC89C52RCRC)OLED显示屏2

每日一言 今天的每一份坚持&#xff0c;都是在为未来积攒底气。 案例&#xff1a;OLED显示一个A 这边观察到一个点&#xff0c;怎么雪花了就是都是乱七八糟的占满了屏幕。。 解释 &#xff1a; 如果代码里信号切换太快&#xff08;比如 SDA 刚变&#xff0c;SCL 立刻变&#…...

Kubernetes 网络模型深度解析:Pod IP 与 Service 的负载均衡机制,Service到底是什么?

Pod IP 的本质与特性 Pod IP 的定位 纯端点地址&#xff1a;Pod IP 是分配给 Pod 网络命名空间的真实 IP 地址&#xff08;如 10.244.1.2&#xff09;无特殊名称&#xff1a;在 Kubernetes 中&#xff0c;它通常被称为 “Pod IP” 或 “容器 IP”生命周期&#xff1a;与 Pod …...

OCR MLLM Evaluation

为什么需要评测体系&#xff1f;——背景与矛盾 ​​ 能干的事&#xff1a;​​ 看清楚发票、身份证上的字&#xff08;准确率>90%&#xff09;&#xff0c;速度飞快&#xff08;眨眼间完成&#xff09;。​​干不了的事&#xff1a;​​ 碰到复杂表格&#xff08;合并单元…...