yae*_*ael 54 linux networking telnet curl
我们可以使用以下命令来测试telnet VIA端口;在以下示例中,我们测试端口 6667:
[root@kafka03 ~]# telnet kafka02 6667
Trying 103.64.35.86...
Connected to kafka02.
Escape character is '^]'.
^CConnection closed by foreign host
Run Code Online (Sandbox Code Playgroud)
由于在某些机器上我们不能使用 telnet(出于内部原因),有什么替代方法来检查端口,如 telnet?
ste*_*eve 73
Netcat ( nc) 是一种选择。
nc -zv kafka02 6667
Run Code Online (Sandbox Code Playgroud)
-z = 将 nc 设置为简单地扫描监听守护进程,而不实际向它们发送任何数据-v = 启用详细模式小智 36
如果使用 Bash Shell,那么您可以使用其功能来检查端口是打开还是关闭:
(timeout 1 bash -c '</dev/tcp/127.0.0.1/17500 && echo PORT OPEN || echo PORT CLOSED') 2>/dev/null
PORT OPEN
(timeout 1 bash -c '</dev/tcp/127.0.0.1/7500 && echo PORT OPEN || echo PORT CLOSED') 2>/dev/null
PORT CLOSED
Run Code Online (Sandbox Code Playgroud)
请注意,如果服务器在超时 1 秒后没有响应,则命令之间的命令会'中断,因此不会打印任何内容。
Lan*_*dak 26
黄金标准无疑是nmap( nmap.org ),但它通常需要 root 才能获得“最佳结果”。但是,可以使用独立的二进制文件,并且可以以非特权用户身份运行它,只是功能降低。例如,它不是隐蔽syn扫描 ( -sS),而是回退到标准 TCP 连接扫描 ( -sT)。这在功能上等同于 netcat,但具有出色的多主机、加速功能。
一个例子:
not-root$ nmap -sT google.com
Starting Nmap 7.70 ( https://nmap.org ) at 2018-11-04 21:01 GMT
Nmap scan report for google.com (172.217.23.14)
Host is up (0.12s latency).
rDNS record for 172.217.23.14: lhr35s01-in-f14.1e100.net
Not shown: 998 filtered ports
PORT STATE SERVICE
80/tcp open http
443/tcp open https
Run Code Online (Sandbox Code Playgroud)
小智 11
“卷曲”可以让生活更轻松。无需root;curl 在所有 linux 系统上都可以使用
1)如果端口未打开将显示以下输出
[niti@SourceServerName ~]$ curl -vv telnet://DestinationServerName:80
* About to connect() to DestinationServerName port 80 (#0)
* Trying 192.168.0.100...
Run Code Online (Sandbox Code Playgroud)
2)如果端口打开将显示在输出下方
[niti@SourceServerName ~]$ curl -vv telnet://DestinationServerName:443
* About to connect() to DestinationServerName port 443 (#0)
* Trying 192.168.0.100...
* Connected to DestinationServerName (192.168.0.100) port 443 (#0)
Run Code Online (Sandbox Code Playgroud)
CtrlC 退出
如果 Perl 是一个选项,您可以使用它的IO::Socket模块来测试与特定主机和端口的连接;下面的脚本将 TCP 硬编码为协议(这是 telnet 将使用的):
#!/usr/bin/perl -w
# tries to connect to the given IP and port (tcp)
use strict;
use IO::Socket;
my $desthost = shift or die "Usage: $0 host port\n";
my $destport = shift or die "Usage: $0 host port\n";
gethostbyname($desthost) || die "Invalid host given\n";
my $handle = IO::Socket::INET->new(
PeerAddr => $desthost,
PeerPort => $destport,
Proto => 'tcp')
or die "can't connect to $desthost:$destport: $!\n";
close $handle;
print "Success!\n"
Run Code Online (Sandbox Code Playgroud)
来自关闭端口的示例输出:
$ ./above-script kafka02 6667
can't connect to kafka02:6667: Connection refused
Run Code Online (Sandbox Code Playgroud)
来自开放端口的示例输出:
$ ./above-script kafka02 4200
Success!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
82712 次 |
| 最近记录: |