linux 测试端口通不通(四种方法)

针对Linux系统:有1、2、3、4四种方法
针对Windows系统:有2、5两种通用方法
一般情况下使用"telnet ip port"判断端口通不通,其实测试方法不止这一种,还有很多种方法,下面小编给大家分享了几种方法,具体内容请往下看:

准备环境

启动一个web服务器,提供端口.

[[email protected] ~]$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 ...

  

用其它web服务器提供端口也一样,由于python比较方便,这里就用它

1、使用telnet判断

telnet是windows标准服务,可以直接用;如果是linux机器,需要安装telnet.

用法: telnet ip port

1)先用telnet连接不存在的端口

[[email protected] ~]# telnet 10.0.250.3 80
Trying 10.0.250.3...
telnet: connect to address 10.0.250.3: Connection refused #直接提示连接被拒绝
2)再连接存在的端口

[[email protected]st ~]# telnet localhost 22
Trying ::1...
Connected to localhost. #看到Connected就连接成功了
Escape character is ‘^]‘.
SSH-2.0-OpenSSH_5.3
a
Protocol mismatch.
Connection closed by foreign host.

2、使用ssh判断

ssh是linux的标准配置并且最常用,可以用来判断端口吗?

用法: ssh -v -p port [email protected]

-v 调试模式(会打印日志).

-p 指定端口

username可以随意

1)连接不存在端口

[[email protected] ~]# ssh 10.0.250.3 -p 80
ssh: connect to host 10.0.250.3 port 80: Connection refused
[[email protected] ~]# ssh 10.0.250.3 -p 80 -v
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 10.0.250.3 [10.0.250.3] port 80.
debug1: connect to address 10.0.250.3 port 80: Connection refused
ssh: connect to host 10.0.250.3 port 80: Connection refused
2)连接存在的端口

[[email protected] ~]# ssh ... -p

[[email protected] ~]# ssh ... -p -v
OpenSSH_.p, OpenSSL ..e-fips Feb
debug: Reading configuration data /etc/ssh/ssh_config
debug: Applying options for *
debug: Connecting to ... [...] port .
debug: Connection established.
debug: permanently_set_uid: /
debug: identity file /root/.ssh/identity type -
debug: identity file /root/.ssh/identity-cert type -
debug: identity file /root/.ssh/id_rsa type -
debug: identity file /root/.ssh/id_rsa-cert type -
debug: identity file /root/.ssh/id_dsa type -
debug: identity file /root/.ssh/id_dsa-cert type -

不用-v选项也可以咯

3、使用wget判断

wget是linux下的下载工具,需要先安装.

用法: wget ip:port

1)连接不存在的端口

[[email protected] ~]# wget ...:
---- ::-- http://.../
Connecting to ...:... failed: Connection refused.
2)连接存在的端口

[[email protected] ~]# wget ...:
---- ::-- http://...:/
Connecting to ...:... connected.
HTTP request sent, awaiting response...

4、使用端口扫描工具

[[email protected] ~]# nmap ... -p
Starting Nmap . ( http://nmap.org ) at -- : CST
Nmap scan report for ...
Host is up (.s latency).
PORT STATE SERVICE
/tcp closed http
MAC Address: B:A::CF:FD:D (Unknown)
Nmap done: IP address ( host up) scanned in . seconds
[[email protected] ~]# nmap ... -p
Starting Nmap . ( http://nmap.org ) at -- : CST
Nmap scan report for ...
Host is up (.s latency).
PORT STATE SERVICE
/tcp open http-proxy
MAC Address: B:A::CF:FD:D (Unknown)
Nmap done: IP address ( host up) scanned in . seconds
[[email protected] ~]# nmap ...
Starting Nmap . ( http://nmap.org ) at -- : CST
Nmap scan report for ...
Host is up (.s latency).
Not shown: closed ports
PORT STATE SERVICE
/tcp open ssh
/tcp open rpcbind
/tcp open http-proxy
/tcp open unknown
MAC Address: B:A::CF:FD:D (Unknown)
Nmap done: IP address ( host up) scanned in . seconds

5、使用专用工具tcping进行访问:

下载软件地址:https://elifulkerson.com/projects/tcping.php,如果无法下载可以从本人资源中下载

总结

提供端口服务,则使用了tcp协议,上面是以web服务器为例。如果服务器是更简单的tcp服务器,三个工具同样适用.

三个工具的共同点是:1.以tcp协议为基础;2.能访问指定端口. 遵循这两点可以找到很多工具.

一般在windows下使用tcping比较方便,linux下个人就比较喜欢用wget.

原文地址:https://www.cnblogs.com/chengkanghua/p/11046999.html

时间: 2024-07-30 01:55:36

linux 测试端口通不通(四种方法)的相关文章

linux下配置ip地址四种方法(图文方法)

配置ip地址四种方法,方便学习linux的朋友 参考学习:ifconfig命令详解  http://zhaoshilei.blog.51cto.com/6455149/1895771 (1)Ifconfig命令   第一种使用ifconfig命令配置网卡的ip地址.此命令通常用来零时的测试用,计算机启动后 ip地址的配置将自动失效.具体用法如下.Ipconfig  ethx   ipadd    netmask      x.x.x.x. 其中ethx中的x代表第几快以太网卡,默认第一块为0.i

linux下配置ip地址四种方法(图文)

(1)Ifconfig命令 第一种使用ifconfig命令配置网卡的ip地址.此命令通常用来零时的测试用,计算机启动后 ip地址的配置将自动失效.具体用法如下.Ipconfig  ethx   ipadd    netmask     x.x.x.x. 其中ethx中的x代表第几快以太网卡,默认第一块为0.ipadd代表ip地址.x.x.x..x为子网掩码.例如给网卡eth0配置的ip地址为192.168.1.1 子网掩码为 255.255.255.0 .如下下图所 注意(此方法配置的ip地址后

linux下查看mysql版本的四种方法

Linux查看MySQL版本的四种方法 1 在终端下执行 mysql -V 2 在help中查找 mysql --help |grep Distrib 3 在mysql 里查看 select version() 4 在mysql 里查看 status 原文地址:https://www.cnblogs.com/apolloren/p/9955158.html

自学Linux命令的四种方法

自学Linux命令的四种方法 导读 童鞋们刚接触linux时,在学习过程中中会遇到不少问题,学习linux摸不着头脑,那么下面介绍四种linux的学习方法,特别适合新手. 方法一:终端"每日提示" 在.bashrc中(/home/.bashrc)增加如下一行: echo "Did you know that:"; whatis$(ls /bin | shuf -n 1) 你只需要增加这行就够了!如果你想让它更娱乐化一些,你可以安装cowsay.Ubuntu/Debi

linux安装IPython四种方法

IPython是Python的交互式Shell,提供了代码自动补完,自动缩进,高亮显示,执行Shell命令等非常有用的特性.特别是它的代码补完功能,例如:在输入zlib.之后按下Tab键,IPython会列出zlib模块下所有的属性.方法和类.完全可以取代自带的bash 下面介绍下linux安装IPython四种方法: 第一种:ipython源码安装ipython的源码下载页面为:https://pypi.python.org/pypi/ipython 或者是到git页面下载:https://g

Linux下计算字符串长度的四种方法

在linux运维场景中,经常会碰到计算字符长度的场景,这里罗列四种方法: [[email protected] ~]# char="I love you" 方法一:[[email protected] ~]# echo ${#char} 方法二:[[email protected] ~]# expr length "$char" 方法三:[[email protected] ~]# echo $char|wc -L 方法四:[[email protected] ~]

如何测试服务器端口通不通

经常会遇到测试服务器端口通不通的情况,在window上常用的是Telnet,不过Linux下Telnet是需要安装的. 一般情况下使用"telnet ip port"判断端口通不通,其实不止这一种,还有很多种方法: 准备环境 启动一个web服务器,提供端口. ? 1 2 [[email protected] ~]$ python -m SimpleHTTPServer 8080 Serving HTTP on 0.0.0.0 port 8080 ... 用其它web服务器提供端口也一样

Fedora安装qt总结四种方法

在fedora上安装qt有四种方法,本人由于初次接触fedora,所以还是耐心的把三个方法都测试了一遍. 1.  下载源码,手动编译,选择路径安装,请参考<fedora15下搭建QT开发环境及编译QT>,博主亲测通过. 优点:       可以自主选择需要的qt版本可以自主选择安装路径 缺点: 编译耗时,其次需要手动安装很多依赖库. 2.  通过yum命令安装,请参考<yum安装qt>,这个其实和第四种方法本质是一样的,一个命令式,一个通过界面而已. sudo yum instal

20150503 imx257下实现I2C驱动的四种方法

20150503 imx257下实现I2C驱动的四种方法 2015-05-3 Lover雪儿 时间过得好快,转眼间五一假期就即将结束了,假期期间,大家都潇洒的去玩了,徒留辛辛苦苦的程序员还是窝在宿舍乖乖的敲着代码... 好啦,开开玩笑,辛酸史每家都有一大本,还是要积极的面对生活!!! 今天我们的任务是简单的入门linux内核下i2c设备驱动分离的四种写法. 一.一个简单的i2c驱动 和以前的驱动程序不同,i2c驱动分为drv驱动和dev设备驱动两个文件,不懂的可以参考我以前写的<20150313