Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use netccat in Linux

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use netccat in Linux, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

netccat is a tool (command) for reading and writing data in the network through TCP/UDP, known as the "Swiss Army Knife", mainly used in the debugging field, transmission field and even hacking field. Using this tool, you can send complete data from one end of the network to another host terminal for display or storage. Common applications are file transfer, instant messaging with friends, streaming media transmission, or as an independent client for authenticating servers.

1. Netcat syntax

First use nc -h command to view the function description:

nc [-46DdhklnrStUvzC] [-i Interval] [-p Source Port][-s Source IP Address] [-T Service Type] [-w Timeout] [-X Proxy Protocol][-x Proxy Address [: Port]] [Host Name] [Port [s]]123 Key Parameters Introduction: -4 Force nc to use only IPv4 addresses. - 6 Force nc to use IPv6 addresses only. - h Print nc help information. - i Interval Specifies an interval between transmission and reception. It also causes delays when connecting multiple interfaces. - z Zero-I/O mode [used for scanning] netcat uses 0-IO, immediately closes the connection after successful connection, does not exchange data-v refers to detailed output-n tells netcat not to use DNS to reverse query IP address domain name II. Netcat function example

nc(netcat) can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, scan ports, handle IPv4 and IPv6. The nc script differs from telnet(1) in that it outputs error messages to standard error output rather than standard output.

1. simple chat

On the Server side:

nc -lp 88881

At this time, the default is TCP connection, listening on port 8888 at Localhost. On the Client side:

nc -nv 127.0.0.1 88881

The test results are as follows:

The client connects to port 8888 of the server through TCP, sends hello, and the server replies OK to it, after which they can communicate with each other.

//chen shuo simple usage://local server listening nc -l 1234//client nc localhost 123412345

Use Ctrl+C(or D) to exit

Of course, you can also test it with telnet command: telnet localhost 8888

2) If it is to test the communication between two hosts in the local area network, the client can connect to the IP address of the Remote host. The command reads:

nc -nv 113.54.154.215 88881

3) To observe the internal implementation of a TCP standard connection, i.e., a three-way handshake and a four-way wave, we monitor a complete connection via tcpdump. When connecting to the local server loopback address, the lo network card is used.

sudo tcpdump -i lo -n tcp port 88881

When connecting to a remote server, use the ens33 network card in the Ubuntu 16.04 environment.

sudo tcpdump -i ens33 -n tcp port 88881

You can clearly see the three-way handshake.

2. port scanning

Port scanning is often used by system administrators and hackers to discover open ports on some machines, helping them identify vulnerabilities in the system. nc can run in TCP or UDP mode, default is TCP, -u parameter is adjusted to udp. Assume that the server has port 8888 open at this point.

The client performs TCP scanning on 10 adjacent ports near 8880 with IP address 113.54.154.215. Client commands are:

nc -nvz 113.54.154.215 8880-88901

The tests are as follows:

2) If UDP scanning is used, the server and client commands are modified as follows: Add the-u option

Server: nc -ulp 8888 Client: nc -unvz 113.54.154.215 8880-889012343. file transfer

Most of the time, we are trying to transfer files over the Internet or through other means. There are many methods, such as FTP,SCP,TFTP,NFS, etc., but when you only need to transfer files temporarily or once, it is really worth wasting time installing and configuring a software on your machine. Suppose you want to pass a file test.cpp from A to B. Either A or B can act as a server or client,

Let A be the server and B be the client. Download files from server A to client B. Server:

nc -lp 8888

Client:

nc -n 113.54.154.215 8888 > test.cc1

Here we create a server on A and redirect netcat's input to the file test.cpp, so that when any successful connection is made to that port, netcat sends the file contents of file. On the client side we redirect the output to test.cc, deliberately because the suffixes of the two files are different, at this point check the file size properties.

At this point, the client redirects the data received by the network to test.cc, or redirects it to/dev/null if the data is not needed. 2) Of course, we can send the client file to the server, and upload test.cc to the server at this time. Server

nc -lp 8888 > test.cc1

Client

nc -n 113.54.154.215 8888

At this point, the files received by the server are redirected to test.cc. We can view the files of the server at this time:

In short, combined with the use of pipes, nc makes it more powerful, such as compressing a directory into

A file that is then piped in with nc to transport the directory.

About "how to use netccat in Linux" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report