测试tcp和udp端口连通性

测试tcp和udp端口连通性

tcp端口

命令 telnet

#测试连接成功
telnet 192.168.126.133 22
Trying 192.168.126.133...
Connected to 192.168.126.133.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4

elnet> q


#测试连接失败
telnet 192.168.126.133 90
Trying 192.168.126.133...


telnet: Unable to connect to remote host: Connection refused

udp端口

命令 nc

#查找提供nc命令的安装包
[root@module ~]# yum provides nc
已加载插件:fastestmirror
源 'zgf' 在配置文件中未指定名字,使用标识代替
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Determining fastest mirrors
2:nmap-ncat-6.40-13.el7.x86_64 : Nmap's Netcat replacement
源    :zgf
匹配来源:
提供    :nc
 
#安装
[root@module ~]# yum -y install nmap-ncat-6.40-13.el7.x86_64

#查看帮助信息
[root@module ~]# nc --help

[root@module ~]# man nc

nc命令用法

Usage: ncat [options] [hostname] [port]			#用法:ncat[选项][主机名][端口]

Options taking a time assume seconds. Append 'ms' for milliseconds,		#花费时间的选项以秒为单位。附加“ms”毫秒,
's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).		#“s”表示秒,“m”表示分钟,或“h”表示小时(例如500ms)。
  -4						 Use IPv4 only								#仅使用IPv4
  -6                         Use IPv6 only								#仅使用IPv6
  -U, --unixsock             Use Unix domain sockets only				#仅使用Unix域套接字
  -C, --crlf                 Use CRLF for EOL sequence					#对EOL序列使用crlf
  -c, --sh-exec <command>    Executes the given command via /bin/sh		#通过/bin/sh执行给定命令
  -e, --exec <command>       Executes the given command					#执行给定的命令
      --lua-exec <filename>  Executes the given Lua script				#执行给定的lua脚本
  -g hop1[,hop2,...]         Loose source routing hop points (8 max)	#松散源路由跳点(最大8个)
  -G <n>                     Loose source routing hop pointer (4, 8, 12, ...)	#松散源路由跃点指针(4,8,12,…)
  -m, --max-conns <n>        Maximum <n> simultaneous connections		#最大同时连接数<n>
  -h, --help                 Display this help screen					#显示此帮助屏幕
  -d, --delay <time>         Wait between read/writes					#读取/写入之间的等待
  -o, --output <filename>    Dump session data to a file				#将会话数据转储到文件
  -x, --hex-dump <filename>  Dump session data as hex to a file			#将会话数据作为十六进制转储到文件
  -i, --idle-timeout <time>  Idle read/write timeout					#空闲读/写超时
  -p, --source-port port     Specify source port to use					#指定要使用的源端口
  -s, --source addr          Specify source address to use (doesn't affect -l)	#指定要使用的源地址(不影响 -l)
  -l, --listen               Bind and listen for incoming connections	#绑定并侦听传入连接
  -k, --keep-open            Accept multiple connections in listen mode	#在侦听模式下接受多个连接
  -n, --nodns                Do not resolve hostnames via DNS			#不通过DNS解析主机名
  -t, --telnet               Answer Telnet negotiations					#回答telnet协商
  -u, --udp                  Use UDP instead of default TCP				#使用udp而不是默认TCP
      --sctp                 Use SCTP instead of default TCP			#使用sctp而不是默认TCP
  -v, --verbose              Set verbosity level (can be used several times)	#设置详细级别(可以多次使用)
  -w, --wait <time>          Connect timeout							#连接超时
  -z                         Zero-I/O mode, report connection status only		#零I/O模式,仅报告连接状态
      --append-output        Append rather than clobber specified output files	#追加而不是删除指定的输出文件
      --send-only            Only send data, ignoring received; quit on EOF		#仅发送数据,忽略已接收数据;在EOF上退出
      --recv-only            Only receive data, never send anything				#仅接收数据,从不发送任何内容
      --allow                Allow only given hosts to connect to Ncat			#仅允许给定主机连接到Ncat
      --allowfile            A file of hosts allowed to connect to Ncat			#允许连接到Ncat的主机文件
      --deny                 Deny given hosts from connecting to Ncat			#拒绝给定主机连接到Ncat
      --denyfile             A file of hosts denied from connecting to Ncat		#拒绝连接到Ncat的主机文件
      --broker               Enable Ncat's connection brokering mode			#启用Ncat的连接代理模式
      --chat                 Start a simple Ncat chat server					#启动一个简单的Ncat聊天服务器
      --proxy <addr[:port]>  Specify address of host to proxy through			#指定要代理的主机地址
      --proxy-type <type>    Specify proxy type ("http" or "socks4" or "socks5")	#指定代理类型(“http”或“socks4”或“socks5”)
      --proxy-auth <auth>    Authenticate with HTTP or SOCKS proxy server		#使用HTTP或SOCKS代理服务器进行身份验证
      --ssl                  Connect or listen with SSL							#使用ssl连接或侦听
      --ssl-cert             Specify SSL certificate file (PEM) for listening	#指定用于侦听的ssl证书文件(PEM)
      --ssl-key              Specify SSL private key (PEM) for listening		#指定用于侦听的ssl私钥(PEM)
      --ssl-verify           Verify trust and domain name of certificates		#验证证书的信任和域名
      --ssl-trustfile        PEM file containing trusted SSL certificates		#包含受信任ssl证书的ssl信任文件PEM文件
      --ssl-ciphers          Cipherlist containing SSL ciphers to use			#密码包含要使用的ssl密码的密码列表
      --version              Display Ncat's version information and exit		#显示Ncat的版本信息并退出

See the ncat(1) manpage for full options, descriptions and usage examples		#有关完整选项、说明和使用示例,请参阅ncat(1)手册页

nc命令man帮助示例

EXAMPLES	#示例
			#example.org 表示主机名
       Connect to example.org on TCP port 8080.		#连接到example.orgTCP的端口8080
           ncat example.org 8080

       Listen for connections on TCP port 8080.		#侦听TCP端口8080上的连接
           ncat -l 8080

       Redirect TCP port 8080 on the local machine to host on port 80.		#将本地计算机上的TCP端口8080重定向到端口80上的主机
           ncat --sh-exec "ncat example.org 80" -l 8080 --keep-open

       Bind to TCP port 8081 and attach /bin/bash for the world to access freely.	#绑定到TCP端口8081并附加/bin/bash,让世界自由访问
           ncat --exec "/bin/bash" -l 8081 --keep-open

       Bind a shell to TCP port 8081, limit access to hosts on a local network, and limit the maximum number of simultaneous connections to 3.	#将shell绑定到TCP端口8081,限制对本地网络上主机的访问,并将同时连接的最大数量限制为3
           ncat --exec "/bin/bash" --max-conns 3 --allow 192.168.0.0/24 -l 8081 --keep-open

       Connect to smtphost:25 through a SOCKS4 server on port 1080.		#通过端口1080上的SOCKS4服务器连接到smtphost:25
           ncat --proxy socks4host --proxy-type socks4 --proxy-auth user smtphost 25

       Create an HTTP proxy server on localhost port 8888.		#在本地主机端口8888上创建HTTP代理服务器
           ncat -l --proxy-type http localhost 8888

       Send a file over TCP port 9899 from host2 (client) to host1 (server).	#通过TCP端口9899从主机2(客户端)向主机1(服务器)发送文件
           HOST1$ ncat -l 9899 > outputfile		#输出文件

           HOST2$ ncat HOST1 9899 < inputfile	#输入文件

       Transfer in the other direction, turning Ncat into a “one file” server.	#向另一个方向传输,将Ncat变成“一个文件”服务器。
           HOST1$ ncat -l 9899 < inputfile

           HOST2$ ncat HOST1 9899 > outputfile


nc默认tcp协议,使用udp要指定u

#目标主机 开启侦测udp端口
nc -vulp 323
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Listening on :::323
Ncat: Listening on 0.0.0.0:323


#测试主机 测试udp端口  成功标志succeeded!
nc -zvu 192.168.126.133 323
Connection to 192.168.126.133 323 port [udp/*] succeeded!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值