Linux上安装NetCat

netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据。通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它。使用netcat命令所能完成的事情令人惊讶。

netcat所做的就是在两台电脑之间建立链接并返回两个数据流,在这之后所能做的事就看你的想像力了。你能建立一个服务器,传输文件,与朋友聊天,传输流媒体或者用它作为其它协议的独立客户端。

下面是一些使用netcat的例子.

[A(172.31.100.7) B(172.31.100.23)]

安装方式一:yum安装
yum install -y netcat

[root@iZbp143t3oxhfc3ar7jey0Z ~]# yum install -y netcat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * webtatic: uk.repo.webtatic.com
No package netcat available.
Error: Nothing to do

 

安装方式二:编译安装

[root@iZbp143t3oxhfc3ar7jey0Z ~]# ll
total 801808
-rw-r--r-- 1 root  root        245 Mar 12 15:09 aaa.text
-rw------- 1 root  root  500336640 Feb 21 22:15 elasticsearch.tar
drwxr-xr-x 4 root  root       4096 Mar  3 13:57 littleTools
drwxr-xr-x 2 root  root       4096 Feb 17 21:39 mysql-5.6.35-linux-glibc2.5-x86_64
-rw-r--r-- 1 root  root  314581668 Feb 17 21:38 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
-rw-r--r-- 1 root  root     398872 Mar 16 00:29 netcat-0.7.1.tar.gz
-rw-r--r-- 1 root  root     399029 Mar 16 00:28 netcat-0.7-persist.rar
drwxrwxr-x 5 test1 test1      4096 Feb 21 19:41 ngx_openresty-1.9.7.1
-rw-r--r-- 1 root  root    3548444 Dec 25  2015 ngx_openresty-1.9.7.1.tar.gz
-rw-r--r-- 1 root  root       1062 Mar  6 00:07 passwd
drwxrwxr-x 6 root  root       4096 Mar 13 12:50 redis-4.0.12
-rw-r--r-- 1 root  root    1740544 Dec 12  2018 redis-4.0.12.tar.gz
[root@iZbp143t3oxhfc3ar7jey0Z ~]# rm -rf netcat-0.7-persist.rar
[root@iZbp143t3oxhfc3ar7jey0Z ~]# tar -zxvf netcat-0.7.1.tar.gz -C /usr/local/
netcat-0.7.1/
netcat-0.7.1/m4/
netcat-0.7.1/m4/lib-link.m4
netcat-0.7.1/m4/inttypes_h.m4
netcat-0.7.1/m4/lcmessage.m4
netcat-0.7.1/m4/inttypes.m4
netcat-0.7.1/m4/lib-ld.m4
netcat-0.7.1/m4/inttypes-pri.m4

进入解压之后的目录

[root@iZbp143t3oxhfc3ar7jey0Z ~]# cd /usr/local/netcat-0.7.1/
[root@iZbp143t3oxhfc3ar7jey0Z netcat-0.7.1]# ll
total 688
-rw-r--r-- 1 100 users  24687 Aug 17  2002 ABOUT-NLS
-rw-r--r-- 1 100 users 109116 Jan 12  2004 aclocal.m4
-rw-r--r-- 1 100 users    473 Nov  5  2003 AUTHORS
-rw-r--r-- 1 100 users  12282 Jan 12  2004 ChangeLog
-rwxr-xr-x 1 100 users  42037 Jan 12  2004 config.guess
-rw-r--r-- 1 100 users   7737 Jan 12  2004 config.h.in
-rwxr-xr-x 1 100 users  14108 May  1  2002 config.rpath
-rwxr-xr-x 1 100 users  30305 Jan 12  2004 config.sub
-rwxr-xr-x 1 100 users 316783 Jan 12  2004 configure
-rw-r--r-- 1 100 users   5814 Jan  4  2004 configure.ac
-rw-rw-r-- 1 100 users  17992 May  4  2002 COPYING
drwxrwxrwx 3 100 users   4096 Jan 12  2004 doc
-rw-r--r-- 1 100 users   9240 Oct  3  2002 INSTALL
-rwxr-xr-x 1 100 users   7122 Jan 12  2004 install-sh
drwxrwxrwx 3 100 users   4096 Jan 12  2004 lib
drwxrwxrwx 2 100 users   4096 Jan 12  2004 m4
-rw-r--r-- 1 100 users    917 Jan  4  2003 Makefile.am
-rw-r--r-- 1 100 users  17855 Jan 12  2004 Makefile.in
-rwxr-xr-x 1 100 users  10270 Jan 12  2004 missing
-rwxr-xr-x 1 100 users   1988 Jan 12  2004 mkinstalldirs
-rw-r--r-- 1 100 users   6143 Jan 12  2004 NEWS
drwxrwxrwx 2 100 users   4096 Jan 12  2004 po
-rw-r--r-- 1 100 users   1041 Dec 31  2003 README
drwxrwxrwx 2 100 users   4096 Jan 12  2004 src
-rw-r--r-- 1 100 users   2197 Aug 29  2003 TODO
[root@iZbp143t3oxhfc3ar7jey0Z netcat-0.7.1]#  ./configure -prefix=/usr/local/netcat
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
[root@iZbp143t3oxhfc3ar7jey0Z netcat-0.7.1]# make && make install
make  all-recursive
make[1]: Entering directory `/usr/local/netcat-0.7.1'
Making all in m4
make[2]: Entering directory `/usr/local/netcat-0.7.1/m4'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/usr/local/netcat-0.7.1/m4'
Making all in lib
make[2]: Entering directory `/usr/local/netcat-0.7.1/lib'
Making all in contrib
make[3]: Entering directory `/usr/local/netcat-0.7.1/lib/contrib'
[root@iZbp143t3oxhfc3ar7jey0Z netcat-0.7.1]# cd /usr/local/netcat
[root@iZbp143t3oxhfc3ar7jey0Z netcat]# ll
total 16
drwxr-xr-x 2 root root 4096 Mar 16 00:30 bin
drwxr-xr-x 2 root root 4096 Mar 16 00:30 info
drwxr-xr-x 3 root root 4096 Mar 16 00:30 man
drwxr-xr-x 3 root root 4096 Mar 16 00:30 share

 

注:此处的/usr/local/netcat−0.7.1/相当于源码文件,安装成功的文件是/usr/local/netcat,这里可以将/usr/local/netcat−0.7.1/删除注:此处的/usr/local/netcat−0.7.1/相当于源码文件,安装成功的文件是/usr/local/netcat,这里可以将/usr/local/netcat−0.7.1/删除
配置环境变量

export NETCAT_HOME=/usr/local/netcat
export PATH=$PATH:$NETCAT_HOME/bin

重新载入配置文件:

[root@iZbp143t3oxhfc3ar7jey0Z netcat]# vi /etc/profile
[root@iZbp143t3oxhfc3ar7jey0Z netcat]# source /etc/profile

 

测试是否安装成功

[root@iZbp143t3oxhfc3ar7jey0Z netcat]# netcat --help
GNU netcat 0.7.1, a rewrite of the famous networking tool.
Basic usages:
connect to somewhere:  netcat [options] hostname port [port] ...
listen for inbound:    netcat -l -p port [options] [hostname] [port] ...
tunnel to somewhere:   netcat -L hostname:port -p port [options]

Mandatory arguments to long options are mandatory for short options too.
Options:
  -c, --close                close connection on EOF from stdin
  -e, --exec=PROGRAM         program to exec after connect
  -g, --gateway=LIST         source-routing hop point[s], up to 8
  -G, --pointer=NUM          source-routing pointer: 4, 8, 12, ...
  -h, --help                 display this help and exit
  -i, --interval=SECS        delay interval for lines sent, ports scanned
  -l, --listen               listen mode, for inbound connects
  -L, --tunnel=ADDRESS:PORT  forward local port to remote address
  -n, --dont-resolve         numeric-only IP addresses, no DNS
  -o, --output=FILE          output hexdump traffic to FILE (implies -x)
  -p, --local-port=NUM       local port number
  -r, --randomize            randomize local and remote ports
  -s, --source=ADDRESS       local source address (ip or hostname)
  -t, --tcp                  TCP mode (default)
  -T, --telnet               answer using TELNET negotiation
  -u, --udp                  UDP mode
  -v, --verbose              verbose (use twice to be more verbose)
  -V, --version              output version information and exit
  -x, --hexdump              hexdump incoming and outgoing traffic
  -w, --wait=SECS            timeout for connects and final net reads
  -z, --zero                 zero-I/O mode (used for scanning)

Remote port number can also be specified as range.  Example: '1-1024'

 需要压缩包的留言即可。

posted @ 2020-03-16 00:46  天宇轩-王  阅读(1116)  评论(0编辑  收藏  举报