linux

Linux下判断远程主机某端口是否开放方法

2019-08-16  本文已影响0人  小六的昵称已被使用

方法1:wget命令

1.语法

wget 192.168.1.1:8888

2.连接一个开放的端口(虽然这个端口上跑的并不是web服务,但是还是会有提示)

wget 192.168.1.133:3306
--2019-06-11 15:11:40--  http://192.168.1.133:3306/
Connecting to 192.168.1.133:3306... connected.
HTTP request sent, awaiting response... 200 No headers, assuming HTTP/0.9
Length: unspecified
Saving to: ‘index.html’

    [ <=>                                                                                   ] 113         --.-K/s   in 0s      

2019-06-11 15:11:40 (14.8 MB/s) - ‘index.html’ saved [113]

3.连接一个不开放的端口(提示连接拒绝)

    [15:11:40 root@ntp ~ #]wget 192.168.1.133:3307
    --2019-06-11 15:11:42--  http://192.168.1.133:3307/
    Connecting to 192.168.1.133:3307... failed: Connection refused.

方法2:ssh 命令

1.语法

ssh -v 192.168.1.1 -p 8888
    -v  显示详细信息

2.连接一个不开放的地址(提示连接拒绝)

## 方法1:加 -v 参数
[15:14:37 root@ntp ~ #]ssh -v 192.168.1.30 -p 3307
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to 192.168.1.30 [192.168.1.30] port 3307.
debug1: connect to address 192.168.1.30 port 3307: Connection refused
ssh: connect to host 192.168.1.30 port 3307: Connection refused

## 方法2:不加 -v 参数(提示连接拒绝)
[15:17:04 root@ntp ~ #]ssh 192.168.1.30 -p 3307
ssh: connect to host 192.168.1.30 port 3307: Connection refused

3.连接一个开放的端口(提示)

## 方法1:加 -v 参数
[15:14:48 root@ntp ~ #]ssh -v 192.168.1.30 -p 3306
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to 192.168.1.30 [192.168.1.30] port 3306.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: ssh_exchange_identification: N
ssh_exchange_identification: Connection closed by remote host

## 方法2:不加 -v 参数(提示连接关闭)
[15:17:02 root@ntp ~ #]ssh 192.168.1.30 -p 3306
ssh_exchange_identification: Connection closed by remote host

方法3:telnet 命令

1.语法

telnet 192.168.1.1 8888

2.连接一个开发的端口(因为这里测试的是一个mysql端口,所以提示的信息里有让输入mysqlpassword的信息)

[15:20:22 root@ntp ~ #]telnet 192.168.1.30 3306
Trying 192.168.1.30...
Connected to 192.168.1.30.
Escape character is '^]'.
N
5.7.22-log(}%LzTgÿ󿾂p3`>Pk4n*mysql_native_password
^CConnection closed by foreign host.

3.连接一个不开放的端口(提示连接拒绝)

[15:20:43 root@ntp ~ #]telnet 192.168.1.30 3307
Trying 192.168.1.30...
telnet: connect to address 192.168.1.30: Connection refused

方法4:nmap命令

1.语法

nmap -v 192.168.1.29 -p 3306

2.测试一个开放的端口(提示:3306/tcp open mysql)

[15:27:08 root@ntp ~ #]nmap 192.168.1.29 -p 3306

Starting Nmap 6.40 ( http://nmap.org ) at 2019-06-11 15:27 CST
Nmap scan report for 192.168.1.29
Host is up (0.00049s latency).
PORT     STATE SERVICE
3306/tcp open  mysql
MAC Address: 00:50:56:B0:28:4B (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds

3.测试一个没有开放的端口(提示:3307/tcp closed opsession-prxy)

[15:27:07 root@ntp ~ #]nmap 192.168.1.29 -p 3307

Starting Nmap 6.40 ( http://nmap.org ) at 2019-06-11 15:27 CST
Nmap scan report for 192.168.1.29
Host is up (0.00050s latency).
PORT     STATE  SERVICE
3307/tcp closed opsession-prxy
MAC Address: 00:50:56:B0:28:4B (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
上一篇 下一篇

猜你喜欢

热点阅读