当前位置:网站首页>"Swiss Army Knife" -nc in network tools
"Swiss Army Knife" -nc in network tools
2022-07-29 07:50:00 【sg-expert】
Check whether the port is occupied
Remember when we were netstat How to check whether the port is occupied ?nc You can do things like that . It USES -l(listen) Parameters , Used to bind a specified port and listen for connections :
$ nc -l 6379
nc: Address already in use
When you see Address already in use When , I know this port is occupied , Otherwise it will listen on this port . Of course, this role is my nonsense , But you can use .
Port scanning
For example, you need to scan a machine 21-30 Which ports are open :
$ nc -n 127.0.0.1 -z 1230-1234 -v
nc: connect to 127.0.0.1 port 1230 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 1231 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 1232 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 1233 (tcp) failed: Connection refused
Connection to 127.0.0.1 1234 port [tcp/*] succeeded!
among -n Direct use of ip Address , Instead of using a domain name ,-z Specify the port range ,-v Output details . As you can see from the results ,1234 Ports are connectable .
TCP/UDP Connect the test
When you're learning TCP Relevant content , Do you think about how to observe the state or data package in your own practice ? Although I recommend myself to write one TCP The server side of the connection - Client program , But you can also use nc Order to complete , for example , Enter the following in a terminal :
$ nc -l 1234
hello Programming pearls
Show in 1234 Port listening , Then you can connect at another terminal ;
$ nc 127.0.0.1 1234
hello Programming pearls
Connect to local address 1234 port , In the process, you can grab bags , analysis TCP Three handshakes .
besides , You can also send messages between established connections ( Simple chat function ), Let you analyze more !
By default , It creates TCP Connect , While using -u(UDP) Parameters can be tested UDP Connectivity .
$ nc -v -u 182.3.226.35 80
Connection to 182.3.226.35 80 port [udp/http] succeeded!
besides , There are also many parameters for debugging , for example :
-b Allow broadcast messages
-D Turn on socket Debug mode
-d Reading from standard input is prohibited
-k After the client exits , Keep connected
-v Show details
Because in the following article will also use nc To illustrate , So I won't go into details here .
HTTP Connect the test
For example, view HTTP Header information :
$ nc www.baidu.com 80
HEAD / HTTP/1.1
HTTP/1.1 302 Found
Connection: Keep-Alive
Content-Length: 17931
Content-Type: text/html
Date: Sun, 23 Jun 2019 13:52:12 GMT
Etag: "54d9748e-460b"
Server: bfe/1.0.8.18
After connection , Input HEAD / HTTP/1.1 or HEAD / HTTP/1.0, Then enter two carriage returns , You can see web Server related information .
The data transfer
Or use the connection from the front , With the help of redirection, you can transfer files , For example, server monitoring , And output the content to out.txt:
$ nc -l 1234 > out.txt
And the client connection :
$ nc 127.0.0.1 1234 < in.txt
So the client in.txt The content of , It will be transmitted to out.txt
Yes, of course , For file transfer ,scp Command can do it better . If you have no other way , You can try nc.
Network testing
As mentioned above, we can pass nc To transmit data , Similarly, if we want to test the network speed between two hosts ( Of course you can use iperf Tools to do the job ),nc It's something we can help with :
# Server monitoring :
$ nc -vl 1234 >/dev/null
Which redirects to /dev/null, It means to discard the data .
And then on another host :
$ dd if=/dev/zero bs=1M count=10 |nc -vn 127.0.0.1 1234
Connection to 127.0.0.1 1234 port [tcp/*] succeeded!
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0333675 s, 314 MB/s
dd Copy the data , From here /dev/zero Copy the data 0, And once 1M, Copy 10 Time , Finally through nc The command is sent to the server . After the end , You can see the statistics .
Create a back door
nc Commands can also be used to create backdoors in the system , And it's a technology that hackers use a lot . To protect our system , We need to know how it works . The command to create a backdoor is :
$ ncat -l 10000 -e /bin/bash
-e The logo will be a bash And port 10000 Connected to a . Now the client only needs to connect to the server 10000 The port can go through bash Get full access to our system :
$ ncat 192.168.1.100 10000
summary
nc The command is short and concise , But it can help us in many ways , for example :
Port scanning
Connect the test
TCP/UDP The server client listens and connects
Network testing
Create a back door
边栏推荐
- [introduction to cryoelectron microscopy] Caltech open class course notes part 3:image formation
- [WPF] realize language switching through dynamic / static resources
- cs61abc分享会(六)程序的输入输出详解 - 标准输入输出,文件,设备,EOF,命令行参数
- Pat class a 1154 vertex shading
- Realize the effect of changing some colors of a paragraph of text
- 【无标题】格式保存
- NLP introduction + practice: Chapter 5: using the API in pytorch to realize linear regression
- 207. Curriculum
- [FPGA tutorial case 42] image case 2 - realize image binarization processing through Verilog, and conduct auxiliary verification through MATLAB
- [paper reading | cryoelectron microscope] interpretation of the new subtomogram averaging method in relion 4.0
猜你喜欢
黑盒测试常见错误类型说明及解决方法有哪些?
![[introduction to cryoelectron microscopy] Caltech open class course notes part 3:image formation](/img/7b/cbd9e3b6d72155613e53ffdd06c5cd.png)
[introduction to cryoelectron microscopy] Caltech open class course notes part 3:image formation

Ionicons icon Encyclopedia

2022年深圳杯A题破除“尖叫效应”与“回声室效应”走出“信息茧房”

Amaze UI 图标查询

监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)

Measured waveform of boot capacitor short circuit and open circuit of buck circuit
What are the principles and methods of implementing functional automation testing?

Android interview question | how to write a good and fast log library?

Monitor the bottom button of page scrolling position positioning (including the solution that page initialization positioning does not take effect on mouse sliding)
随机推荐
[paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching
工业互联网行至深水区,落地的路要怎么走?
JVM garbage collection mechanism (GC)
String类
关于pip升级损坏导致的问题记录
String class
下推分析的限制
Amaze UI 图标查询
写点dp
Cs61abc sharing session (VI) detailed explanation of program input and output - standard input and output, file, device, EOF, command line parameters
[WPF] realize language switching through dynamic / static resources
QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
功能自动化测试实施的原则以及方法有哪些?
My entrepreneurial neighbors
flutter只要是数据,都会判空的
Output 1234 three digits without repetition
Access数据库引入datagridview数据后,显示错误
What is the use of chat robots? What type? After reading these, you will understand!
性能更佳、使用更简单的懒加载IntersectionObserverEntry(观察者)
@Use of jsonserialize annotation