嘗試理解 ping

嘗試理解 ping

我正在編寫一個 Reachability 類別來測試 IP 位址是否有效且可用。我寫了一個單元測試來測試我的課程是否正常運作,然後它就發生了。我使用 IP 位址 192.168.1.255 進行測試,我認為該位址在我的網路中無法訪問,但我得到 IsReachable = true。呃……這怎麼可能?

好吧,我有一個基線。我可以使用 Windows 隨附的“ping”應用程式。這是該測試的結果

# ping 192.168.1.255

Pinging 192.168.1.255 with 32 bytes of data:
Reply from 192.168.1.200: bytes=32 time<1ms TTL=64
Reply from 192.168.1.200: bytes=32 time<1ms TTL=64
Reply from 192.168.1.200: bytes=32 time<1ms TTL=64
Reply from 192.168.1.200: bytes=32 time=1ms TTL=64

Ping statistics for 192.168.1.255:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms

事情變得更奇怪了

# ping 192.168.1.253

Pinging 192.168.1.253 with 32 bytes of data:
Reply from 192.168.1.27: Destination host unreachable.
Reply from 192.168.1.25: Destination host unreachable.
Reply from 137.224.244.1: Destination net unreachable.
Reply from 137.224.244.1: Destination net unreachable.

Ping statistics for 192.168.1.253:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

這裡發生了什麼事?有人可以向我解釋這個結果意味著什麼嗎?

編輯新增的IPCONFIG

ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : DESKTOP-CB16LLI
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : wurnet.nl
                                       home

Ethernet adapter Ethernet 3:

   Connection-specific DNS Suffix  . : wurnet.nl
   Description . . . . . . . . . . . : NCP Secure Client Virtual NDIS6 Adapter
   Physical Address. . . . . . . . . : 02-00-AD-4F-70-18
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 137.224.245.97(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : vrijdag 30 maart 2018 08:20:26
   Lease Expires . . . . . . . . . . : donderdag 17 mei 2018 21:25:51
   Default Gateway . . . . . . . . . :
   DHCP Server . . . . . . . . . . . : 137.224.245.98
   DNS Servers . . . . . . . . . . . : 10.90.3.31
                                       10.91.3.31
   NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter Ethernet 1:

   Connection-specific DNS Suffix  . : home
   Description . . . . . . . . . . . : Surface Ethernet Adapter
   Physical Address. . . . . . . . . : C4-9D-ED-E8-5D-1E
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.1.27(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : vrijdag 30 maart 2018 08:12:39
   Lease Expires . . . . . . . . . . : zaterdag 31 maart 2018 08:12:50
   Default Gateway . . . . . . . . . : 192.168.1.254
   DHCP Server . . . . . . . . . . . : 192.168.1.254
   DNS Servers . . . . . . . . . . . : 192.168.1.254
   NetBIOS over Tcpip. . . . . . . . : Enabled

Wireless LAN adapter Local Area Connection* 1:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
   Physical Address. . . . . . . . . : BE-83-85-E7-C5-48
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
   Physical Address. . . . . . . . . : BC-83-85-E7-C4-4A
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : home
   Description . . . . . . . . . . . : Marvell AVASTAR Wireless-AC Network Controller
   Physical Address. . . . . . . . . : BC-83-85-E7-C4-49
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::49ca:6fd:8fa4:a099%3(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.1.25(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : vrijdag 30 maart 2018 08:12:49
   Lease Expires . . . . . . . . . . : zaterdag 31 maart 2018 08:13:08
   Default Gateway . . . . . . . . . : 192.168.1.254
   DHCP Server . . . . . . . . . . . : 192.168.1.254
   DHCPv6 IAID . . . . . . . . . . . : 79463301
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-22-4C-14-89-C4-9D-ED-E8-5D-1E
   DNS Servers . . . . . . . . . . . : fe80::2aff:3eff:fe3d:f5%3
                                       192.168.1.254
   NetBIOS over Tcpip. . . . . . . . : Enabled

Tunnel adapter Local Area Connection* 11:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

編輯以上 ping 是在 VPN 連線開啟的情況下進行的。以下是 VPN 連線關閉的情況

ping 192.168.1.253

Pinging 192.168.1.253 with 32 bytes of data:
Reply from 192.168.1.27: Destination host unreachable.
Reply from 192.168.1.27: Destination host unreachable.
Reply from 192.168.1.27: Destination host unreachable.
Reply from 192.168.1.27: Destination host unreachable.

答案1

0255不是 255.255.255.0 子網路中機器所在的有效位址。

255 是「廣播」位址,0 是「網路位址」。

相關閱讀為什麼IP位址不能以0或255開頭?。答案解決了寬 IP 位址的廣泛情況,但該規則也適用於子網路位址,因此對於 255.255.255.0 子網,保留第一個和最後一個 IP。


關於第一個 ping 中的 ping 操作.253,它本質上是詢問它擁有的每個網路適配器是否有到主機的路由。

在其中兩個案例中,他們的回复Destination host unreachable.實質上是說“如果它在這裡,我們會讓您知道,但由於某種原因無法訪問”

更奇怪的是 VPN 網路網關,Destination net unreachable.在這種情況下,它表示由於子網路劃分和其他因素,它絕對無法與之通訊任何機器在該網路上。

你的最終 ping 看起來就像我期望看到的那樣。您的本機網路介面卡只是告訴您該位址無法存取。

答案2

ICMP 協定直接在 IPv4 之上運作(在本例中)。它具有與單播 UDP 或 TCP 不同的路由規則。基本上任何看到 ICMP 封包的主機都可以回答(甚至撒謊)。

因此,您在收到的資料包計數中看到的不僅僅是目的地的回應。

相關內容