Skip to content

Note

文件更新時間: 20230202

How To: 建立及驗證 ICMP/TCP/UDP 連線

關於 ICMP

使用 ping

command.sh
ping -c2 www.microsoft.com
success_output
$ ping -c2 www.microsoft.com
PING e13678.dscb.akamaiedge.net (23.208.81.153) 56(84) bytes of data.
64 bytes from a23-208-81-153.deploy.static.akamaitechnologies.com (23.208.81.153): icmp_seq=1 ttl=59 time=12.10 ms
64 bytes from a23-208-81-153.deploy.static.akamaitechnologies.com (23.208.81.153): icmp_seq=2 ttl=59 time=10.10 ms

--- e13678.dscb.akamaiedge.net ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 10.950/11.974/12.998/1.024 ms
failed_output
$ ping -c2 ww.microsoft.com
ping: ww.microsoft.com: Name or service not known

使用 mtr

command.sh
mtr www.microsoft.com
output
$ mtr www.microsoft.com
rhel8 (172.29.13.134)                                                                                                   2023-01-31T14:22:12+0800
Keys:  Help   Display mode   Restart statistics   Order of fields   quit
                                                                                                        Packets               Pings
 Host                                                                                                 Loss%   Snt   Last   Avg  Best  Wrst StDev
 1. _gateway                                                                                           0.0%     5    0.3   0.3   0.2   0.4   0.1
 2. 192.168.100.254                                                                                    0.0%     5    2.9   2.9   2.6   3.3   0.3
 3. h254.s98.ts.hinet.net                                                                              0.0%     4   21.5  16.0  12.3  21.5   4.1
 4. tpdb-3332.hinet.net                                                                                0.0%     4   12.0  12.7  11.9  14.1   1.0
 5. 210.59.225.230                                                                                     0.0%     4   17.5  27.8  11.4  66.0  25.6
 6. a23-208-81-153.deploy.static.akamaitechnologies.com                                                0.0%     4   10.7  11.1  10.6  11.7   0.5
failed_output
$ mtr ww.microsoft.com
mtr: Failed to resolve host: ww.microsoft.com: Name or service not known

關於 TCP

80/TCP, 443/TCP

使用 Nmap

command.sh
nmap -sT -p 80,443 www.microsoft.com
success_output
$ nmap -sT -p 80,443 www.microsoft.com
Starting Nmap 7.70 ( https://nmap.org ) at 2023-01-31 14:25 CST
Nmap scan report for www.microsoft.com (23.208.81.153)
Host is up (0.014s latency).
Other addresses for www.microsoft.com (not scanned): 2001:b034:1c:388::356e 2001:b034:1c:384::356e 2001:b034:1c:381::356e 2001:b034:1c:385::356e 2001:b034:1c:383::356e
rDNS record for 23.208.81.153: a23-208-81-153.deploy.static.akamaitechnologies.com

PORT    STATE SERVICE
80/tcp  open  http
443/tcp open  https

Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
failed_output
$ nmap -sT -p 22 www.microsoft.com
Starting Nmap 7.70 ( https://nmap.org ) at 2023-01-31 14:31 CST
Nmap scan report for www.microsoft.com (23.208.81.153)
Host is up (0.011s latency).
Other addresses for www.microsoft.com (not scanned): 2001:b034:1c:389::356e 2001:b034:1c:388::356e 2001:b034:1c:387::356e 2001:b034:1c:382::356e
rDNS record for 23.208.81.153: a23-208-81-153.deploy.static.akamaitechnologies.com

PORT   STATE    SERVICE
22/tcp filtered ssh

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

使用 Netcat

command.sh
# z: zero-I/O mode which is used for scanning
# v: for verbose output
# w3: timeout wait 10 seconds

nc -zvw3 www.microsoft.com 80
nc -zvw3 www.microsoft.com 443
success_output
$ nc -zvw3 www.microsoft.com 80
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connected to 23.208.81.153:80.
Ncat: 0 bytes sent, 0 bytes received in 0.04 seconds.

$ nc -zvw3 www.microsoft.com 443
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connected to 23.208.81.153:443.
Ncat: 0 bytes sent, 0 bytes received in 0.04 seconds.
failed_output
$ nc -zvw3 www.microsoft.com 22
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to 23.208.81.153 failed: Connection timed out.
Ncat: Trying next address...
Ncat: Connection to 2001:b034:1c:383::356e failed: Network is unreachable.
Ncat: Trying next address...
Ncat: Connection to 2001:b034:1c:382::356e failed: Network is unreachable.
Ncat: Trying next address...
Ncat: Connection to 2001:b034:1c:38a::356e failed: Network is unreachable.
Ncat: Trying next address...
Ncat: Connection to 2001:b034:1c:381::356e failed: Network is unreachable.
Ncat: Trying next address...
Ncat: Network is unreachable.

使用 curl

command.sh
curl www.cs.nycu.edu.tw:80 --connect-timeout 3
curl www.cs.nycu.edu.tw:443 --connect-timeout 3
success_output
$ curl www.cs.nycu.edu.tw:80 --connect-timeout 3
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

$ curl www.cs.nycu.edu.tw:443 --connect-timeout 3
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx</center>
</body>
</html>
failed_output
$ curl www.cs.nycu.edu.tw:81 --connect-timeout 3
curl: (7) Failed to connect to www.cs.nycu.edu.tw port 81: No route to host

使用 Telnet

TBD

關於 UDP

53/UDP

使用 Nmap

command.sh
sudo nmap -sU -p 53 168.95.1.1
sudo nmap -sU -p 53 168.63.129.16 # (1)
  1. Azure-provided DNS servic
success_output
$ sudo nmap -sU -p 53 168.95.1.1
Starting Nmap 7.70 ( https://nmap.org ) at 2023-01-31 15:11 CST
Nmap scan report for dns.hinet.net (168.95.1.1)
Host is up (0.016s latency).

PORT   STATE SERVICE
53/udp open  domain

Nmap done: 1 IP address (1 host up) scanned in 0.78 seconds
failed_output
$ sudo nmap -sU -p 80 168.95.1.1
Starting Nmap 7.70 ( https://nmap.org ) at 2023-01-31 15:11 CST
Nmap scan report for dns.hinet.net (168.95.1.1)
Host is up (0.014s latency).

PORT   STATE         SERVICE
80/udp open|filtered http

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