Nc:a test cmd for TCP HTTP

Source: Internet
Author: User
Tags unix domain socket

You need a NC test environment on Docker--internet some data collected on the

---------------------------------------------------------------------------------

Swiss Army Knife NC//man that's clear.

Common uses include:

· Simple TCP Proxies
· Shell-script based HTTP clients and servers
· Network Daemon Testing
· A SOCKS or HTTP proxycommand for SSH (1)
· And much, much more

TCP:hosta:$ nc-l 1234 hostb:$ NC hostA 1234//use for chatting

Date transfer hosta:$ nc-l 1234 > T.out hostb:$ NC hostA 1234 < t.in

Http:hosta Apache on//get post

[[Email protected] voh]# NC 192.168.110.135 < t.t
http/1.1 OK
date:wed, 05:50:28 GMT
server:apache/2.2.27 (Unix)
Last-modified:sat, 2004 20:16:24 GMT
ETag: "c4d07-2c-3e9564c23b600"
Accept-ranges:bytes
Content-length:44
Keep-alive:timeout=5, max=100
Connection:keep-alive
Content-type:text/html

http/1.1 OK

....

post /scripts/nsiislog.dll http/1.1
host: www.test.com
content-length: 16758
user-agent: mozilla/5.0  (windows; u; windows nt 5.0; zh-cn; rv:1.9.0.4 )  gecko/2008102920 firefox/3.0.4
Accept: text/html,application/xhtml+xml,application/xml;q= 0.9,*/*;q=0.8
accept-language: zh-cn,zh;q=0.5
accept-encoding: gzip,deflate
Accept-Charset:  gb2312,utf-8;q=0.7,*;q=0.7
keep-alive: 300
connection: keep-alive
Cookie:  Aspsessionidaqdbsaqa=ldabjfedgccinnbjmhnnpkdi
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa AAAAAAAAAAAAAAAAAAAAA

Scan
Linux-f1ao:/home/voh # nc-v-W 192.168.110.135-z 21-25
Nc:connect to 192.168.110.135 port (TCP) Failed:connection refused
Connection to 192.168.110.135 Port [Tcp/ssh] succeeded!
Nc:connect to 192.168.110.135 port (TCP) Failed:connection refused

--------------------------------------------------------------------------------------------------------------- --------------

Source URL

http://blog.csdn.net/wang7dao/article/details/7684998

NetCat, a "Swiss Army Knife" in Web tools, has a version of Windows and Linux. Because it is short and short (the 1.84 version is 25k, the old version or the reduced version is even smaller), functional, is designed as a simple, reliable network tool, can transmit read and write data through TCP or UDP protocol. At the same time, it is a network application debug parser, because it can create a variety of different types of network connections as needed.

First, version
The usual Linux distributions come with Netcat (NC), and even in rescue mode discs, BusyBox provides a simple version of the NC tool. But different versions, the use of their parameters slightly different.
NetCat Official Address: http://netcat.sourceforge.net/

references [[email protected] ~]# cat/etc/asianux-release
Asianux Release 2.0 (Trinity SP2)
[Email protected] ~]# cat/etc/redflag-release
Red Flag DC Server Release 5.0 (Trinity SP2)
[[email protected] ~]# type-a NC
NC IS/USR/BIN/NC
[[email protected] ~]# rpm-q NC
Nc-1.10-22


It is recommended to use man NC to see help before using. Here is a brief description of the 1.10 version on red Flag DC Server 5.0.
Assume two server information:

Reference server1:192.168.228.221
server2:192.168.228.222


Second, the common use
1. Remote Copy File

Copy files from Server1 to Server2. Need to first on the Server2, with NC activation monitoring, Server2 run:

references [[email protected] tmp]# NC-LP 1234 > Install.log


Run on Server1:

references [[email protected] ~]# ll Install.log
-rw-r--r--1 root root 39693 December Install.log
[Email protected] ~]# nc-w 1 192.168.228.222 1234 < Install.log


2. Clone a hard disk or partition
The operation is identical to the copy above, only the data of the hard disk or partition must be obtained by DD and then transferred.
Cloning the operation of a hard disk or partition should not take place on a system already on mount. Therefore, after booting with the installation disc, enter rescue mode (or use the Knoppix tool CD) to boot the system and perform a similar listening action on the Server2:

# nc-l-P 1234 | DD OF=/DEV/SDA


Perform the transfer on Server1 to complete the task of cloning the SDA hard drive from Server1 to Server2:

# DD IF=/DEV/SDA | NC 192.168.228.222 1234


※ The prerequisite for completing the above work is to implement the CD rescue mode to support the network card on the server and properly configure the IP.

3. Port Scan

Can perform:

Ref # NC-V-W 1 192.168.228.222-z 1-1000
Hatest2 [192.168.228.222] (SSH) Open


4. Save the Web page

# while true; Do Nc-l-P 80-q 1 < somepage.html; Done



5. Analog HTTP Headers

references [[email protected] ~]# NC www.linuxfly.org 80
get/http/1.1
Host:ispconfig.org
Referrer:mypage.com
User-agent:my-browser

http/1.1 OK
Date:tue, Dec 07:23:24 GMT
server:apache/2.2.6 (Unix) dav/2 mod_mono/1.2.1 mod_python/3.2.8 python/2.4.3 mod_perl/2.0.2 Perl/v5.8.8
SET-COOKIE:PHPSESSID=BBADORBVIE1GN037IIH6LRDG50; path=/
expires:0
Cache-control:no-store, No-cache, Must-revalidate, post-check=0, pre-check=0
Pragma:no-cache
Cache-control:private, Post-check=0, pre-check=0, max-age=0
Set-cookie:own_sid=xrutay; Expires=tue, 23-dec-2008 07:23:24 GMT; path=/
Vary:accept-encoding
Transfer-encoding:chunked
Content-type:text/html
[......]


After the NC command, enter the contents of the Red section and press ENTER two times to get the HTTP headers content from the other side.

6. Chat
NC can also be used as a simple word hyphenating chat tool, the same, server2 need to start monitoring:

[Email protected] tmp]# NC-LP 1234



Server1 on transfer:

[[Email protected] ~]# NC 192.168.228.222 1234


In this way, the two sides can communicate with each other. Use Ctrl+d to exit normally.

7. Transmission Directory
Copy nginx-0.6.34 directory contents from Server1 to Server2. Need to first on the Server2, with NC activation monitoring, Server2 run:

references [[email protected] tmp]# nc-l 1234 |tar XZVF-


Run on Server1:

references [[email protected] ~]# ll-d nginx-0.6.34
Drwxr-xr-x 8 4096 12-23 17:25 nginx-0.6.34
[Email protected] ~]# tar czvf-nginx-0.6.34|nc 192.168.228.222 1234


8. Introduction of parameters
This is just a simple description of the 1.10 version, with detailed parameters to use or to look at the man:

References want to connect to somewhere: NC [-options] hostname port[s] [ports] ...
Bind port Waiting for connection: Nc-l-P Port [-options] [hostname] [port]
Parameters:
-G Gateway source-routing Hop Point[s], up to 8
-G num source-routing pointer:4, 8, 12, ...
-H Help Information
-I secs delay interval
-L listening mode for inbound connections
-n Specifies the IP address of the number and cannot be used hostname
-O file record 16-binary transfer
-P port Local port number
-R arbitrarily specify local and remote ports
-S addr Local Source Address
-U UDP mode
-V Verbose output--with two-V for more detailed content
-W secs timeout time

-Z turns the input and output off-when used for scanning, where the port number can specify one or a specified range of Lo-hi.


9, 1.84 version of the parameters introduction1. NC [ -46DDHKLNRSTUUVZC] [-I interval] [-p source_port]
2. [-S source_ip_address] [-t ToS] [-w timeout] [-X Proxy_protocol] [-X
3. proxy_address[:p ort] [hostname] [port[s]]

1.-4 mandatory use of IPv4
2.-6 mandatory use of IPv6
3.-D allows socket communication to return debug information
4.-D does not allow reading from standard input
5.-H Display NC Help document
6.-I interval
7. Specify the content delay between each line send and accept, also can make the connection between multiple ports delay
8.-K When a connection ends, force the NC to listen for another connection. Must be used with-l
9.-L is used to listen for incoming data links and cannot be used with-p-z-S. The timeout for the-W parameter is also ignored
Ten.-N does not perform any address, hostname, port or DNS query
One.-p Specifies the source port that the NC uses, restricted by permissions, and cannot be used with the-l
-r Specifies the source and destination ports that are used by the NC and cannot use those ports that the system originally specified
-S allows TCP MD5 signature options in RFC 2385
-S Source_ip_address
15. Specify the IP address of the interface used for the contract, and cannot be used with-l
-T ToS
17. Specify the IP service type of the link (TOS)
-C Line Wrapping
-T enables NC to interact with Telnet
-U using a UNIX domain socket
-U uses UDP instead of the default TCP option
Full-V Output verbose report
. W Timeout
24. A link does not operate for a period of time, then automatically disconnects, default no timeout
-X Proxy_version
26. Specify the protocol used by the NC to use the proxy, optionally with SOCKSV4,SOCKS5 and HTTPS. Default SOCKS5
X.-x proxy_address[:p ORT]
28. Specify the proxy address and port that NC uses. Default settings: SOCKS, 3128 (HTTPS)
-Z-only monitoring does not send any packets


Third, version differences
There is a slight difference in the use of the parameters provided by the NC versions that are not available on the system.
For example, the red Flag Asianux 3.0 SP1 Rescue CD version is available for use with only a subset of the parameters:

Reference # Nc-h
BusyBox v1.2.0 (2008.04.14-01:35+0000) multi-call binary

USAGE:NC [OPTIONS] [IP] [port]

Netcat opens a pipe to Ip:port

Options:
-L Listen mode, for inbound connects
-P PORT Local PORT number
-I SECS delay interval for lines sent
-e PROG program-to-exec after connect (dangerous!)
-W SECS timeout for connects and final net reads


The NC version provided in the Asianux 3.0 SP1 system is 1.84, which is not executed according to the above parameter usage:

references [[email protected] ~]# rpm-q NC
Nc-1.84-10
[Email protected] ~]# NC-LP 1234
USAGE:NC [ -46DDHKLNRSTUUVZC] [-I interval] [-p source_port]
[-S source_ip_address] [-T ToS] [-w timeout] [-X Proxy_version]
[-X proxy_address[:p ORT]] [hostname] [Port[s]]


To view the man document, it is visible in this version,-L is not used with-s,-P,-Z, and the-w parameter is ignored, so the correct usage is:

[Email protected] tmp]# nc-l 1234



Iv. use in Scripts
Each time the NC starts listening, the server exits as soon as the client connection completes and exits. So, if you need to constantly use NC for data transfer, you need to use loops in your scripts. Using NC For more functionality, refer to the reference script provided by its RPM:

Reference # RPM-QD NC
/usr/share/doc/nc-1.10/changelog
/usr/share/doc/nc-1.10/readme
/usr/share/doc/nc-1.10/scripts/readme
/usr/share/doc/nc-1.10/scripts/alta
/usr/share/doc/nc-1.10/scripts/bsh
/usr/share/doc/nc-1.10/scripts/dist.sh
/usr/share/doc/nc-1.10/scripts/irc
/usr/share/doc/nc-1.10/scripts/iscan
/usr/share/doc/nc-1.10/scripts/ncp
/usr/share/doc/nc-1.10/scripts/probe
/usr/share/doc/nc-1.10/scripts/web
/usr/share/doc/nc-1.10/scripts/webrelay
/usr/share/doc/nc-1.10/scripts/websearch
/usr/share/man/man1/nc.1.gz

Nc:a test cmd for TCP HTTP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.