Is IP address on the same subnet as the local machine (with IPv6 support)

前端 未结 4 1354
无人及你
无人及你 2020-12-18 06:37

Does anyone have some code that will determine if an IP address (IPv4 or IPv6) is on the same subnet as the machine running the application? I\'ve seen numerous examples of

4条回答
  •  忘掉有多难
    2020-12-18 06:56

    In 99% of the cases, this is simple. All subnets in IPv6 are /64 prefixes therefore if the leftmost 64 bits of a prefix are identical, they are in the same subnet.

    Now it is true that some people are doing wierd things and making subnets with longer prefixes but the majority of this is dealing with point-to-point circuits where they use a /126 to number the two endpoints and then RESERVE the /64 containing the /126. An application would never run into this situation since no servers are involved.

    There is no good reason to support subnet sizes other than /64.

提交回复
热议问题