美文网首页
扫描服务器上未占用的端口并用于python

扫描服务器上未占用的端口并用于python

作者: CrimsonUMO | 来源:发表于2023-09-26 18:24 被阅读0次

扫描端口

下载好Xshell后,再下载安装一个nmap插件。下载地址:

https://nmap.org/download.html

安装完成后,打开shell,不用登录服务器,直接在本地运行命令

nmap 192.168.33.16 -p 8700

-p 参数在nmap里意思是扫描指定的端口,当然后面也可以写一个范围,比如8700-8888。

返回的结果代表端口的状态。如:

Starting Nmap 7.94 ( https://nmap.org ) at 2023-09-26 09:57 中国标准时间
Nmap scan report for localhost (192.168.33.16)
Host is up (0.0076s latency).

PORT     STATE  SERVICE
8700/tcp closed unknown

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

显示了扫描的时间、用时、端口号、状态、当前运行的服务等。

此外还可以查看这个端口以前的历史版本

nmap-sv-p 8700 192.168.33.16

返回结果

Starting Nmap 7.94 ( https://nmap.org ) at 2023-09-26 10:09 中国标准时间
Nmap scan report for localhost (192.168.33.16)
Host is up (0.0078s latency).

PORT     STATE  SERVICE VERSION
8700/tcp closed unknown

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.74 seconds

扫描结果可能会有如下几种情况:

  1. 如果端口开放,会显示出检测到的服务名称及版本号,例如 ssh 1.2.3等。

  2. 如果端口关闭,会显示端口状态为 closed。

  3. 如果端口有保护,扫描无法直接获取服务详情,会显示端口状态为 filtered。

  4. 如果服务版本无法检测,会显示端口状态为 open,但服务名称和版本为 unknown。

通过观察扫描结果,如果发现端口上有服务名称和版本号,则可以判定该端口很可能已被某服务占用。

打开端口

如果是python的话,在shell里安装好jupyterlab后,通过jupyterlab命令可以自动开启指定的端口。

jupyter lab --ip=0.0.0.0 --port=8700 --no-browser

相关文章

网友评论

      本文标题:扫描服务器上未占用的端口并用于python

      本文链接:https://www.haomeiwen.com/subject/sxkcbdtx.html